0

When I try to transfer the form data to PHP file with this code:

index.html (the form):

<!DOCTYPE html>
<html>
  <body>
    <form action="welcome.php" method="post">
      First name:<br>
      <input type="text" name="fname" value="Mickey">
      <br>
      Last name:<br>
      <input type="text" name="lname" value="Mouse">
      <br><br>
      <input type="submit" value="Submit">
    </form> 
  </body>
</html>

and the welcome.php is:

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

when I press on the submit button I get the "welcome.php" content back:

enter image description here

why? and how could I fix it ?

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Dor Eliyahu
  • 37
  • 1
  • 7

2 Answers2

0

As others stated in comments. It doesn't appear to be anything wrong with your code besides the fact that your PHP file is being opened just as a normal file.

Install XAMPP if you're running the code on your local machine so it knows what to do with the PHP file.

DMort
  • 347
  • 1
  • 2
  • 10
  • I downloaded XAMPP and I close skype and etc.. and I still cannot "Start" apache or MySql .. 20:48:02 [mysql] Problem detected! 20:48:02 [mysql] Port 3306 in use by ""C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" MySQL"! 20:48:02 [mysql] MySQL WILL NOT start without the configured ports free! 20:48:02 [mysql] You need to uninstall/disable/reconfigure the blocking application 20:48:02 [mysql] or reconfigure MySQL and the Control Panel to listen on a different port – Dor Eliyahu May 31 '16 at 17:49
  • Did you disable any antivirus when you installed XAMPP? Make sure you are installing XAMPP as an Administrator as well. Sometimes uninstalling and reinstalling works too. – DMort May 31 '16 at 18:40
  • Something is already using that port. You can change the port in the .ini file. See if you can follow these instructions from this question and let me know how it works out for you. http://stackoverflow.com/questions/18177148/xampp-mysql-does-not-start – DMort May 31 '16 at 18:41
0

PHP is a server-side language and browsers are unable to interpret it. It exists to provide the server with a way to work with data that you do not want the user to have access to.

Therefore, to run the PHP code you need to load the site files from a server, which will interpret and run the code and only deliver the results to the users browser.

This is how it works in a nutshell - user tries to load example.com/index.php in a browser, the browser finds the IP address of the server via DNS (Domain Name Server) and requests the content from the server. When the server receives the request it will find your welcome.php file and start sending it to the browser. At that point the server will also interpret all the php code inside the file and send only the results in your echo to the user.

For testing purposes you can avoid having to buy a domain and web hosting by making your own local server with a tool like XAMPP, which is available for Windows, Linux and OS X. Setting up the server is quite easy and once you do that you can load your files by loading localhost in your browser.

PeterTheLobster
  • 1,386
  • 16
  • 33