0

I just started learning php today (this is basically copy/pasted from the w3schools tutorial).

This is the html file:

<html>
<body>
<form action="test.php" method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
</form>

And this is the php file:

<html>
<body> 
Welcome <?php echo $_POST["name"]; ?>    
<br>    
Your email address is: <?php echo $_POST["email"]; ?>    
</body>
</html>

I've downloaded xampp but when I try to submit the form, I get the following:

Welcome

Your email address is:

So it seems like $_POST is empty... any ideas why this might be? Thanks!

EDIT: Moved the files to the xampp htdocs folder, it works now. Thanks everyone!!

Jenny
  • 9
  • 3
  • Check to see if the inputs are entered using `isset` before `echo`ing. – Script47 Jan 11 '16 at 21:56
  • 3
    You can also `var_dump($_POST)` or `var_dump($_REQUEST)` to see if any values exist at all. – aynber Jan 11 '16 at 21:57
  • 1
    have you input something in those text fields? – harrrrrrry Jan 11 '16 at 21:59
  • 1
    webserver/PHP installed? accessed how as `http://yourhost/file.xxx` or as `c://file.xxx`? those are 2 different animals altogether. – Funk Forty Niner Jan 11 '16 at 21:59
  • If you view the source are the PHP blocks in the code? – chris85 Jan 11 '16 at 22:01
  • Your PHP script file or any script with PHP code in it must have a `.php` extension. Beware, if you are using `notepad.exe` it adds a `.txt` extension so your file may be names `xxxxx.php.txt` Dont use notepad to edit php source – RiggsFolly Jan 11 '16 at 22:06
  • @RiggsFolly Yes, it does have a .php extension. – Jenny Jan 11 '16 at 22:23
  • @chris85 yes, the php blocks are in the code (for the page I get after submitting) – Jenny Jan 11 '16 at 22:28
  • @Fred-ii- I access the file by double clicking the .html file, and I think xampp includes php? – Jenny Jan 11 '16 at 22:28
  • 1
    So you double `.html` on your desktop (or wherever) and it opens in a browser as `http` or `file:///`? I don't know windows well but it sounds like you are bypassing the PHP processing in your current execution flow. – chris85 Jan 11 '16 at 22:38
  • You're not accessing your pages through your web server (xampp) – Eeji Jan 11 '16 at 22:39
  • Run the page from your browser like any other web page, using `localhost/file.php` or if you have the script in a subfolder of htdocs use `localhost/subfolder/file.php` Unless you do this the PHP compiler will not be invoked – RiggsFolly Jan 11 '16 at 22:41

0 Answers0