$_GET Variable
The predefined $_GET variable is used to collect values from the form with method="get".
The information sent from a form with the GET method is visible to everyone (will be displayed in the browser's address bar), and there is a limit on the amount of information sent.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> get </title> </head> <body> <form method="get" action="name.php"> 用户名:<input type="text" placeholder="请输入用户名" name="name"><br> 密 码:<input type="password" placeholder="请输入密码" name="pwd"><br> <input type="submit" value="提交"><br> </form> </body> </html>
Next we create a new name.php file to receive form submissions
<?php
$name = $_GET['name' ];
$pwd = $_GET['pwd'];
?>
In this way, the content submitted by the form is received, and then we look at the address bar Changes Using the get method will display the content submitted by the form just now in the address bar
Then we use the post method to submit
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> get </title> </head> <body> <form method="post" action="name.php"> 用户名:<input type="text" placeholder="请输入用户名" name="name"><br> 密 码:<input type="password" placeholder="请输入密码" name="pwd"><br> <input type="submit" value="提交"><br> </form> </body> </html>
The post method to receive the code is as follows
<?php
$name = $_POST['name'];
$pwd = $_POST['pwd'];
?>
Same We also need to use name.php to receive the information submitted by the form. Pay attention to the changes in the address bar. If you use the post method, the address bar will not change and the content of the form will not be displayed.
Note: These two pieces of code require everyone to Create two files yourself and put them on the local server for testing
Next Section