Home >Backend Development >PHP Tutorial >Use PHP's super variable $_POST to obtain HTML Form data_PHP tutorial

Use PHP's super variable $_POST to obtain HTML Form data_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:29:301032browse

When the method of the HTML Form is get, $_GET is used to obtain the data of the HTML Form.

When the method of HTML Form is post, $_POST is used to obtain the data of HTML Form.

For the difference between get and post in HTML Form, please refer to the difference between get and post in HTML Form.

Get HTML Form text input box (input type="text") data
The following is an HTML file. This HTML contains an HTML Form, which is mainly used to allow users to enter user names. .

Copy code The code is as follows:




Name:





When you enter your name in the text box input box of this HTML Form , such as "Jacky", and then click the ok button with the mouse, it will jump to post.php, and the output result displayed is You are Jacky. The source code of post.php is as follows:
Copy code The code is as follows:


You are .



Get form control The name value of the form control can be used to obtain the data of the form control.

For example, "username" is the name value of the form control text input box,


Use $_POST[" username"] can obtain the data of the text input box.


Get HTML Form (HTML Form) radio button (input type="radio") data
Get form radio button The name value of the box can be used to obtain the value of the form radio button.

The following is an HTML file containing form radio buttons. The code is as follows:
Copy the code The code is as follows:




Apple

Orange

Mango






In the HTML file, select any item, for example, select "Orange", and then click the ok button, the browser will jump to radiopost.php, and the output result of radiopost.php is Orange. The source code of radiopost.php is as follows:
Copy code The code is as follows:






$_POST["fruit" The fruit in ] is the name value of the form radio button.

Get HTML Form checkbox (input type="checkbox") data
Users can select multiple values ​​through HTML Form checkbox, so $_POST gets more than one value, is an array.

When writing the name value of the HTML Form check box, please note that [ ] must be added at the end of the name value.

The following example, name="fruit[ ]":
Copy code The code is as follows:

< ;html>


Apple

Orange

Mango






The source code of checkboxpost.php is as follows:
Copy code The code is as follows:



echo count($_POST["fruit"]),"
";
foreach ($_POST["fruit"] as $value)
{echo $value,"
";
}
?>



If you select Orange and Mango and click the OK button, the browser will jump to checkboxpost.php, first use the count function to get the array $_POST["fruit" ], if the user selects 2 items, the result will be 2, and then use a foreach loop to output the value of each element of $_POST["fruit"], which is the value of the item selected by the user, Orange and Mango.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323379.htmlTechArticleWhen the method of HTML Form (HTML Form) is get, $_GET is used to obtain the data of HTML Form. When the method of the HTML Form is post, $_POST is used to get the HTML Form's...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn