The $_GET and $_POST variables in PHP are used to retrieve information in a form, such as user input.
Before studying this chapter, you can review the HTML form first
A form is an area containing form elements.
Form elements allow users to enter content in the form, such as text areas, drop-down lists, radio-buttons, checkboxes, etc.
The form uses the form tag <form> to set the
Specific review URL: HTML form
PHP form processing
There is one very important thing worth mentioning Note that when processing HTML forms, PHP can automatically make form elements from the HTML page available to PHP scripts.
Example
The following example contains an HTML form with two input boxes and a submit button.
form.html file code is as follows:
<html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form action="welcome.php" method="post"> 名字: <input type="text" name="fname"> 年龄: <input type="text" name="age"> <input type="submit" value="提交"> </form> </body> </html>
When the user fills out the above form and clicks the submit button, the form data will be sent to the PHP file named "welcome.php" :
welcome.php file is as follows:
Your age is <?php echo $_POST["age"]; ?> years.