It is often necessary to fill in the user name and password on the web page. After clicking the confirmation button, the user name and password are sent to the server after front-end processing. So how does the server obtain the data submitted by these users? is through the super global variable
_POST and _GET
$_GET [] (Recommended learning: PHP programming from entry to proficiency)
Description: Get the data submitted by form method = “get”
Example: $username = $_GET[“username”];
$_POST[]
Description: Get the data submitted by form method = “post”
Example :$username = $_POST[“username”];
Let’s take _POST as an example first.
I wrote the following code in the index.html of my site.
means to create a form. The method used to submit this form is the post method, and new.php will process this form. This form has two input boxes, their names are name and age, and a confirmation button, its name is submit, and the text above the confirmation button is submit.
<form action ="new.php" method = "post" > <p>name:<input type ="text" name= "name"></p> <p>age:<input type = "text" name= "age"></p> <p><input type ="submit" name = "submit" value ="submit"></p> </form>
<?php foreach($_POST as $key =>$value) { echo $key . ' => ' . $value . '<br>'; } ?>
Take _GET as an example again.
<form action ="new.php" method = "get" > <p>name:<input type ="text" name= "name"></p> <p>age:<input type = "text" name= "age"></p> <p><input type ="submit" name = "submit" value ="submit"></p> </form>
The above is the detailed content of How to get form data in php. For more information, please follow other related articles on the PHP Chinese website!