Home  >  Article  >  Backend Development  >  How to use super global variables $_POST and $_GET

How to use super global variables $_POST and $_GET

王林
王林forward
2020-08-04 17:31:442369browse

How to use super global variables $_POST and $_GET

PHP $_POST is widely used to collect form data. Specify this attribute in the HTML form tag: "method="post".

PHP $_GET is also used Widely used to collect form data, specify this attribute in the HTML form tag: "method="get".

(Recommended tutorial: php graphic tutorial)

Example:

The following example shows an input field (input) and submit button (submit ) form. When a user submits form data by clicking the "Submit" button, the form data is sent to the script file specified in the action attribute of the ff9c23ada1bcecdd1a0fb5d5a0f18437 tag.

In this example, we specify the file to process the form data. If you want another PHP file to handle this data, you can modify the specified script file name. We can then use the super global variable $_POST to collect the input field data in the form.

<html>
<body>
 <form method="post" action="<?php echo $_SERVER[&#39;PHP_SELF&#39;];?>">
Name: <input type="text" name="fname">
<input type="submit"></form>
 <?php 
$name = $_POST[&#39;fname&#39;]; 
echo $name; 
?>
</body>
</html>

(Video tutorial recommendation: php video tutorial)

$_GET can also collect the data sent in the URL.

Suppose we have a hyperlinked HTML page containing parameters:

<html>
<body>
<a href="test_get.php?subject=PHP&web=php.com">Test $GET</a>
</body>
</html>

When the user clicks on the link "Test $GET", the parameters "subject" and "web" will be sent to "test_get.php ",You can use the $_GET variable in the "test_get.php" file to get this data.

The following example shows the code of the "test_get.php" file:

<html>
<body>
 <?php 
echo "Study " . $_GET[&#39;subject&#39;] . " @ " . $_GET[&#39;web&#39;];
?>
 </body>
</html>

The above is the detailed content of How to use super global variables $_POST and $_GET. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete