Get HTML form (HTML form) data _php Tutorial with PHP's hyper-variable $_post

Source: Internet
Author: User
When the method of an HTML form (HTML form) is GET, $_get is used to get the data for the HTML form.

When the method for the HTML form (HTML form) is post, $_post is used to get the data for the HTML form.

The difference between get and post for HTML form, see the difference between get and post for HTML form.

Gets the HTML form (HTML form) text input box (input type= "text") data
The following is an HTML file that contains an HTML Form that is used primarily to allow users to enter the user's name.
Copy CodeThe code is as follows:






When you enter the name in the text box of this HTML Form, such as "Jacky", then the mouse click OK button, will jump to post.php, show the output is you is Jacky. The source code for post.php is as follows:
Copy CodeThe code is as follows:


You are .



Takes the name value of the form control to get the data for the form control.

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


Use $_post["username" to get the data for the text input box.


Get HTML form (HTML form) radio box (input type= "Radio") data
You can get the value of the table-only marquee by taking the name value of the form's single box.

The following is an HTML file containing the form box, with the following code:
Copy CodeThe code is as follows:






In the HTML file, choose an option, such as select "Orange", and then click the button OK, the browser will jump to radiopost.php,radiopost.php output is Orange. The source code for radiopost.php is as follows:
Copy CodeThe code is as follows:






The fruit in $_post["fruit" is the name value of the form's marquee.

Get HTML form (HTML form) check box (input type= "checkbox") data
The user can select multiple values through the HTML Form check box, so the $_post gets more than one value, which is the array.

Note that when you write the name value of the HTML Form check box, the name value is added to the last [].

In the example below, name= "fruit[]":
Copy CodeThe code is as follows:






The source code for checkboxpost.php is as follows:
Copy CodeThe code is as follows:


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



If you choose orange and Mango, and click the OK button, the browser will jump to checkboxpost.php, first use the Count function to get the number of elements of the array $_post["fruit"], if the user selected 2 items, the result is 2, and then use The Foreach loop outputs the value of each element of $_post["fruit", which is the value of the item selected by the user, orange and mango.

http://www.bkjia.com/PHPjc/323379.html www.bkjia.com true http://www.bkjia.com/PHPjc/323379.html techarticle when the method of an HTML form (HTML form) is GET, $_get is used to get the data for the HTML form. When the method of the HTML form (HTML form) is post, the $_post is used to get the HTML form ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.