Home > Article > Backend Development > Do you know what php uses to collect form data?
In the previous article, we learned about $_SERVER. If you need it, please read "Teach you how to play with $_SERVER". This time we will introduce to you the method of collecting form data in PHP. You can refer to it if necessary.
In PHP, "$_POST
", "$_GET
" and "$_REQUEST
" are used to collect form information. But this time we will introduce "$_POST" and "$_GET" first. First, let's take a look at "$_POST".
Let’s look at a small case first.
<!DOCTYPE html> <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php $name = htmlspecialchars($_POST['fname']); echo $name; ?> </body> </html>
The result is
As you can see in this example, when we enter information in the input box and click submit , the information we just entered will appear on the page. Let's look at the code again and find that the method attribute value of the form tag is post, and "##" appears between "<?php
" and "?>
" #$_POST['fname']", presumably this is the reason why the form information appears on the page.
The above is the detailed content of Do you know what php uses to collect form data?. For more information, please follow other related articles on the PHP Chinese website!