-2

When I submit my form, I get sent to the correct file as specified in the action attribute of my form, but the PHP in the file isn't printing the variables at all... I've combed through posts of other people having the same issue, but none of their solutions fix my problem. I've stripped my code down to a simple, textbox, button, and a php file that's supposed to print the textbox value.

If it matters, I'm running this locally in chrome, not using any servers or websites yet, I'd like to get my code working locally before I upload to my server.

HTML

<html>

<form action="Submit.php" method="post">
  <input type="text" placeholder="First Name" name="firstName" id="firstName" required> 
  </br></br>

  <input type="submit" name="submitted" value="Submit">
</form>
</html>

PHP

<html>
<body>
    Name <?php echo $_POST["firstName"]; ?><br>
</body>
</html>

All I get when I click the button is a white page with "Name" printed.

Thanks!

Nat
  • 890
  • 3
  • 11
  • 23
  • What do you see if you `View Source`? – Barmar Feb 12 '15 at 01:16
  • Exactly what I have under PHP shows up when I click view source – Nat Feb 12 '15 at 01:18
  • *not using any servers or websites yet* I hope you have a local server. Also please show us your **full** code. What are the file names (+extension)? And are the files in the same dir? Also if you use a local server do you have the files in the server dir + do you call the scripts over the server? – Rizier123 Feb 12 '15 at 01:18
  • 1
    You need a server to execute PHP. If you just access it as a local file, you just get the contents of the script, it won't be executed. – Barmar Feb 12 '15 at 01:18
  • @Barmar that would be my problem then, I didn't know that! If you post an answer, I'll mark it best. – Nat Feb 12 '15 at 01:20
  • @Nathan Is my comment invisible or what? http://stackoverflow.com/questions/28467614/php-post-not-working-correctly#comment45260738_28467614 – Rizier123 Feb 12 '15 at 01:22
  • possible duplicate of [PHP code is not being executed (i can see it on source code of page)](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page) – Rizier123 Feb 12 '15 at 01:24
  • @Rizier123 That's not a duplicate. In that question he's running Apache, it just wasn't configured properly for PHP. – Barmar Feb 12 '15 at 01:26
  • 1
    @Barmar I beg to differ. The question that's marked as a duplicate does mention to install a web server as well as having to point to localhost and not as a file in a web browser. – Funk Forty Niner Feb 12 '15 at 01:43
  • The second paragraph of the question says "Apache is running properly". I don't see any answer that says to install a webserver. The accepted answer starts with "Make sure that PHP is installed" and then goes on to explain how to configure Apache to use it. – Barmar Feb 12 '15 at 01:46
  • 1
    It was suggested a week or so ago, and in another question same as this, that a canonical question be made. @Barmar You and I know just as well, that this type of question gets asked more often than none. I think it would be suitable to do one up, or if one exists, to use that for any future questions such as this. A better duplicate could have been used, I agree, however and again; this type of question gets asked ever so often and will keep on getting asked. – Funk Forty Niner Feb 12 '15 at 01:52

1 Answers1

3

Running scripts in response to HTTP requests is something that's done by the webserver. If you just use local files, the script will simply be loaded into the browser as a text or HTML file, it won't be executed. You can't do form processing like this.

You need to run a local server, then access the form as http://localhost/form.html

Barmar
  • 741,623
  • 53
  • 500
  • 612