$ _ GET is one of PHP super variables.
When the method of HTML Form is get, $ _ GET is used to obtain the data of HTML Form.
Obtain the data in the HTML Form text input box (input type = "text ").
The following is an HTML file. This HTML contains an HTML Form, which is mainly used for users to enter their names.
Copy codeThe Code is as follows:
<Html>
<Head> <title> Blablar.com HTML Form Method Get Example </title> <Body>
<Form action = "get. php" method = "get">
Name: <input type = "text" name = "username"/>
<Input type = "submit" value = "OK"/>
</Form>
</Body>
</Html>
The HTML display interface is as follows:
When you enter a name in the form text box of This HTML file, such as "Jacky", and then click the OK button, it will jump to get. php, as shown in get. php.
The source code of get. php is as follows:
Copy codeThe Code is as follows:
<Html>
<Head> <title> Blablar.com PHP $ _ GET Example </title> <Body>
You are <? Php echo $ _ GET ["username"]?>.
</Body>
</Html>
Obtain the data of the Form Control by taking the name value of the Form Control.
For example, "username" is the name value of the text input box of the Form Control,
Copy codeThe Code is as follows:
<Input type = "text" name = "username"/>
You can use $ _ GET ["username"] to obtain the data in the text input box.
Copy codeThe Code is as follows:
<? Php
Echo $ _ GET ["username"]
?>
Obtain HTML Form (HTML Form) single dataset (input type = "radio") data
You can obtain the value of the single-sheet signature by taking the name value of the single-sheet signature.
The following is an HTML file containing a single sheet. The Code is as follows:
Copy codeThe Code is as follows:
<Html>
<Head> <title> Blablar.com </title> <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>
</Html>
The figure is as follows:
In this HTML file, select any item, such as "Orange", and click "OK". the browser will jump to radio. php, in radio. the result displayed in php is "Orange ". The source code of radio. php is as follows:
Copy codeThe Code is as follows:
<Html>
<Head> <title> Blablar.com </title> <Body>
<? Php echo $ _ GET ["fruit"]?>
</Body>
</Html>
In $ _ GET ["fruit"], fruit is the name value of the form ticket.
Obtain the data of the HTML Form check box (input type = "checkbox ")
You can select multiple values through the HTML Form check box. Therefore, $ _ GET gets more than one value, which is an array.
When writing the name value of the HTML Form check box, note that [] must be added at the end of the name value.
For example, name = "fruit []":
Copy codeThe Code is as follows:
<Html>
<Head> <title> Blablar.com </title> <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>
</Html>
Display Results Of This HTML file
If you select Orange and Mango and click OK, the browser will jump to checkbox. php and display the result.
The source code of checkbox. php is as follows:
Copy codeThe Code is as follows:
<Html>
<Head> <title> Blablar.com </title> <Body>
<? Php
Echo count ($ _ GET ["fruit"]), "<br/> ";
Foreach ($ _ GET ["fruit"] as $ value)
{Echo $ value, "<br/> ";
}
?>
</Body>
</Html>
Use the count function to obtain the number of elements in the array $ _ GET ["fruit"]. If you select two items, the result is 2. Then, use foreach to output $ _ GET ["fruit"] the value of each element, that is, the target value of the user option, Orange and Mango.
The next section describes how to use the PHP super variable $ _ POST to obtain the data of an HTML Form.