Pasting $_POST
Posted on 12. Mar, 2010 by admin in Basics
In the last tutorial we brushed up on our HTML skills. Lets take the code from the last tutorial, and make a small edit.
<html> <head> <title>Flipping Forms Tutorial</title> </head> <body> The following is a form: <br/> <form action="index.php" method="post"> What is your favorite book?: <input type="text" name="book" /><br/> What is your favorite movie?: <input type="text" name="movie" /><br/> What is your favorite website?: <input type="text" name="website" /><br/> <input type="submit" /> </form> </body> </html>
If you didn’t notice the slight change I made was method=”post”. This specifies the type of data our form should send. Now on to the PHP. Putting some text in box and hitting submit is not going to do us much good, so let’s capture it and print it out. Put this PHP code under the </form> tag.
Printed Results:<br/> <?php //Print out our Post Data echo "Favorite Book: ".$_POST["book"]."<br/>"; echo "Favorite Movie: ".$_POST["movie"]."<br/>"; echo "Favorite Website: ".$_POST["website"]."<br/>"; ?>
Sample Output:
Favorite Book: Harry Potter
Favorite Movie: Star Wars
Favorite Website: WildPHP of Course!
As you can see from the code we get the post data and print it out once you hit submit. The simple $_POST["var name"] statement allows us to do that.

