Now it is time to put what we learned about $_GET and $_POST to use. We are going to make a script that prints what you enter into a box onto the screen.
Make a new text file and save it as "post.php" with (use notepad or some similar program - NOT MS Word). Now type the following into it:
if (isset($_POST['text'])) {
/* "if" something was posted (isset) do the following: */
print "You Said: ". $_POST['text'];
}
?>
If you re-save it now and upload it to your web server you will see the something like the following:
<form> Your Text:<input name="text" type="text"> <input type="submit" value="Submit"> </form>
When you enter something into YOUR scripts text box and click "Submit" you will then see it printed out on to the screen below the form. If you right-click onto the screen you will see that only the processed "source code" remains:
<form action="post.php" method="post"> <!--//Make the HTML Form --> Your Text:<input name="text" type="text"> <!--//Make the input box --> <input type="submit" value="Submit"> <!--//Make the Submit button --> </form> <!--// End the Form --> You Said: Hello Everybody!
Now what does each part of this code do? The first part is just a simple HTML Form:
<form action="post.php" method="post"> <!--//Make the HTML Form --> Your Text:<input name="text" type="text"> <!--//Make the input box --> <input type="submit" value="Submit"> <!--//Make the Submit button --> </form> <!--// End the Form -->
There is NO PHP in it - all it does is make the text area and the submit button for the script. Notice the start of the form says "