How to get form data in php

(*-*)浩
Release: 2023-02-25 09:50:01
Original
5049 people have browsed it

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

How to get form data in php

_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>
Copy after login
<?php

foreach($_POST as $key =>$value)
{
    echo $key . &#39; => &#39; . $value . &#39;<br>&#39;;
}
?>
Copy after login

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>
Copy after login
rrree

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template