Using PHP's Super variable $_get to get HTML form data _php base

Source: Internet
Author: User
Tags html form php and
$_get is one of the super variables in PHP.

When the method of the HTML form (HTML form) is GET, $_get is used to obtain the data for the 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 (HTML form) that is used primarily for users to enter user names.
Copy Code code as follows:

<body>
<form action = "get.php" method = ' Get ' >
Name: <input type= "text" name= "username"/>
<input type = "Submit" value= "OK"/>
</form>
</body>

The HTML display interface is as follows:

When you enter the name in the form text box of the HTML file, such as "Jacky", then the mouse clicks the OK button, jumps to the get.php, and the following figure appears in the get.php.

Get.php's source code is as follows:

Copy Code code as follows:

<body>
You are <?php echo $_get["username"]?>.
</body>

You can get the data for the form control by taking the name value of the form control.

For example, "username" is the name value of the form control text input box,
Copy Code code as follows:

<input type= "text" name= "username"/>

Use $_get["username"] to get the data for the text entry box.
Copy Code code as follows:

<?php
echo $_get["username"]
?>

Get HTML form (HTML form) radio box (input type= "Radio") data
Take the name value of the selected box in the table, and you can get the value of the table-only selection box.

Below is an HTML file with a table-only selection box, with the following code:
Copy Code code as follows:

<body>
<form action = "radio.php" method = ' Get ' >
<input type= "Radio" name= "fruit" value = "Apple" >apple</input><br/>
<input type= "Radio" name= "fruit" value = "Orange" >orange</input><br/>
<input type= "Radio" name= "fruit" value = "Mango" >mango</input><br/>
<input type= "Submit" value= "OK" >
</form>
</body>

This is illustrated below:

In the HTML file, select a random item, such as "Orange", and then click the button OK, the browser will jump to radio.php, in the radio.php display result is "orange". Radio.php's source code is as follows:

Copy Code code as follows:

<body>
<?php echo $_get["Fruit"]?>
</body>

The fruit in $_get["fruit" is the name value of the table-only selection box.

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

When you write the name value of the HTML Form check box, note that the name value is finally added [].

The following example, Name= "fruit[]":
Copy Code code as follows:

<body>
<form action = "checkbox.php" method = ' Get ' >
<input type= "checkbox" Name= "fruit[]" value = "Apple" >apple</input><br/>
<input type= "checkbox" Name= "fruit[]" value = "Orange" >orange</input><br/>
<input type= "checkbox" Name= "fruit[]" value = "Mango" >mango</input><br/>
<input type= "Submit" value= "OK" >
</form>
</body>

The HTML file displays the results as shown in figure:

If you choose Orange and Mango and click the OK button, the browser jumps to checkbox.php and displays the results as shown.

Checkbox.php's source code is as follows:

Copy Code code as follows:

<body>
<?php
echo count ($_get["fruit"]), "<br/>";
foreach ($_get["fruit"] as $value)
{echo $value, "<br/>";
}
?>
</body>

The number of elements of the array $_get["fruit" is obtained with the Count function, and if the user chooses 2 items, the result is 2. The value of each element of the $_get["fruit" is then used in a Foreach loop, which is the value of the user's selected item, Orange and Mango.

In the next section we describe the use of PHP super variable $_post to get the data for an HTML form (HTML form).

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.