1. Overview:
The $_GET and $_POST variables in PHP are used to retrieve information in the form, such as user input.
2. PHP form processing
One very important thing to note is that when processing HTML forms, PHP can process the data from the HTML page. The form elements in are automatically made available for use by PHP scripts.
Example: The code is as follows
The following example contains an HTML form with two input boxes and a submit button.
<html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <!-- 新建一个带有两个输入框和一个提交按钮的表单 --> <!-- action为提交的的那个页面,method为提交方式,有$POST和$GET两种 --> <form action="" method="post"> 名字: <input type="text" name="name"> <br/> 年龄: <input type="text" name="age"> <br/> <input type="submit" value="提交"> <hr> 大家好,我是 <?php echo $_POST["name"]; ?>!<br> 今年 <?php echo $_POST["age"]; ?> 岁。 </form> </body> </html>
The output is as shown on the right
More details, we will explain in the next section
3. Form Validation
Under no circumstances should user-submitted data be considered in good faith, so user input should be verified whenever possible (via the client script). Browser validation is faster and reduces the load on the server.
If user input needs to be inserted into the database, you should consider using server validation. A good way to validate a form on the server is to pass the form to itself, rather than jumping to a different page. This way users can get error messages on the same form page. It will be easier for users to find errors.
Learning experience:
# There are two basic forms submission methods: $GET and $POST, both of which implement the same function. , but the implementation process is different. We will discuss it in detail in the next few sections.
Form verification is required at any time.
Remember to enable apache