1

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!

asked Nov 15, 2013 at 2:18
3
  • 2
    It seems like you don't have a webserver installed... Commented Nov 15, 2013 at 2:21
  • What output do you get? Or do you not get any output at all? Commented 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. Commented Nov 15, 2013 at 2:27

2 Answers 2

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:

answered Nov 15, 2013 at 2:22
Sign up to request clarification or add additional context in comments.

6 Comments

So how do I go about installing a server so that this works? This is likely a dumb question, but I really don't have any background at all! Thanks.
@user2994585 what OS are you running, Mac, Windows, Linux?
@user2994585 then just download the mamp server and install it, be sure to put your files in the htdocs
Just did that -- downloaded MAMP and put the two files (index.html and submit.php) in the htdocs file. Then I went to chrome and opened index.html, filled out the form and hit submit. Same thing, not getting the right output...
Yes, I did, and I have two green lights for both servers. What do I type into the URL slot of Chrome/Safari/etc in order to properly open the file?
|
1

Sounds 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.

answered Nov 15, 2013 at 2:24

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.