I'm very new to php/html, and I'm trying to teach myself the basics of creating and processing an html form.
I created a folder called Website. In it I created an html file index.html. I also created a file submit.php.
(this code is taken from: http://www.w3schools.com/php/php_forms.asp)
In index.html I have:
<html>
<body>
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
In submit.php I have:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
When I open the html file in chrome and fill in the blanks and press submit, I get redirected to a page with the code in submit.php:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
I should be getting this output:
Welcome Hannah
Your email address is [email protected]
What am I doing wrong that the output isn't working? Thanks!
-
2It seems like you don't have a webserver installed...Henrique Barcelos– Henrique Barcelos2013年11月15日 02:21:10 +00:00Commented Nov 15, 2013 at 2:21
-
What output do you get? Or do you not get any output at all?randomusername– randomusername2013年11月15日 02:21:59 +00:00Commented Nov 15, 2013 at 2:21
-
Side note, for when you get it working. You should use htmlspecialchars when outputting user input, for security reasons. Check the answer here.Matthew Johnson– Matthew Johnson2013年11月15日 02:27:48 +00:00Commented Nov 15, 2013 at 2:27
2 Answers 2
PHP is processed on a server, so you can't treat it like HTML, it needs to be placed on a server that has apache installed. You can install one on your computer, using something like the following:
6 Comments
htdocsSounds like you are doing this via files on your desktop and not via a web server. Either on the Internet or via your local machine. I took your example 100% as presented, placed it within my htdocs folder in MAMP (LAMP for the Macintosh) and it behaves 100% as expected.
The difference between loading files on your desktop versus a web server is a web server will process the PHP. If you just do it as files, then the file gets loaded & doesn’t get parsed.