A useful feature of PHP is the way it handles PHP forms. The very important principle you need to understand is that any elements of the form will automatically take effect in your PHP script. See "Variables outside of PHP" in this manual for more information and examples of using forms in PHP. Here is an example of an HTML form:
Example: a simple HTML form
<form action="action.php" method="POST">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="submit">
</form>
There is nothing special about the form, which does not use any special identifiers. When the user fills out the form and clicks on the Submit button, the page action.php will be invoked. In this file, you can add the following:
Example: Print data from a form
Hi <?php echo $_POST["name"]; ?>.
You are <?php echo $_POST["age"]; ?> years old.
The output of this script might be:
Hi Joe.
You are 22 years old.
The script's work should already be clear, and there is no more complex content. PHP will automatically set the $_post["name" and $_post["age" variables for you. Before that we used the automatic global variable $_server, and now we've introduced the automatic global variable $_post, which contains all the POST data. Notice how our form submits the data (method). If we can use the Get method, the information in the form will be stored in the automatic global variable $_get. If you are not concerned with the source of the request data, you can also use the automatic global variable $_request, which contains all the data for GET, POST, COOKIE, and FILE.
This example is just an example of getting started! Provides a quick way into the world of PHP.