Home >Backend Development >PHP Tutorial >Summary of steps to obtain form in PHP_PHP tutorial
Summary of PHP get form method
When PHP accepts information submitted through an HTML form, it will save the submitted data in a global array. We can call the system-specific automatic global variable array to obtain these values. Commonly used automatic global variables are as follows:
$_GET
$_POST
$_REQUEST
In obtaining form data, the most commonly used automatic global variables are $_GET and $_POST, which obtain data submitted through the GET method and data submitted through the POST method respectively. For example, if a text box form control named "txtAge" is submitted using the GET method, you can use
$_GET["txtAge"] or $_GET['txtAge']
Get the value it submitted.
$_REQUEST automatic global variable contains all GET, POST, COOKIE and FILE data. If you don’t care about the data source, you can use
$_REQUEST["txtAge"] or $_REQUEST['txtAge'] to get the submitted data.
The following is a simple example of obtaining submitted data:
<?php echo("你的帐号是:" . $_POST['login']); //输出帐号 echo("<br>"); echo("你的姓名是:" .$_POST['yourname'] ); //输出姓名 echo( "<br>"); echo("你的密码是:" . $_POST['passwd'] ); //输出密码 echo("<br>"); echo("你的查询密码问题是:" . $_POST['question'] ); //查询密码问题 echo("<br>"); echo("你的查询密码答案是:" . $_POST['question2'] ); //查询密码答案 echo("<br>"); echo("你的出生日期是:" . $_POST['byear'] ."年". $_POST['bmonth'] . "月" . $_POST['bday'] . "日" ); //出生日期 echo("<br>"); echo("你的性别是:" . $_POST['gender']); //性别 echo("<br>"); echo("你的爱好是:<br>" ); //爱好 foreach ($_POST['hobby'] as $hobby) { echo($hobby . "<br>"); } ?> 相应的表单代码如下: <html> <head> <title> 用户调查表 </title> </head> <body> 欢迎光临本网站,请首先输入以下个人资料:<br> <form method=post action="baidu.php"> 帐号:<INPUT maxLength=25 size=16 name=login><br> 姓名:<INPUT type=password size=19 name=yourname ><br> 密码:<INPUT type=password size=19 name=passwd ><br> 确认密码:<INPUT type=password size=19 name=passwd ><br> 查询密码问题:<br> <select name=question> <option selected value="">--请您选择--</option> <option value="我的宠物名字?">我的宠物名字?</option> <option value="我最好的朋友是谁?">我最好的朋友是谁?</option> <option value="我最喜爱的颜色?">我最喜爱的颜色?</option> <option value="我最喜爱的电影?">我最喜爱的电影?</option> <option value="我最喜爱的影星?">我最喜爱的影星?</option> <option value="我最喜爱的歌曲?">我最喜爱的歌曲?</option> <option value="我最喜爱的食物?">我最喜爱的食物?</option> <option value="我最大的爱好?">我最大的爱好?</option> </select> <br> 查询密码答案:<input name="question2" size="18"><br> 出生日期: <select name="byear" id="BirthYear" tabindex=8> <?php for($i=1930;$i<=2009;$i++){ echo "<option value='$i'>" . $i ."年</option>"; } ?> </select> <select name="bmonth" id="BirthYear" tabindex=8> <?php for($i=1;$i<=12;$i++){ echo "<option value='$i'>" . $i ."月</option>"; } ?> </select> <select name="bday" id="BirthYear" tabindex=8> <?php for($i=1;$i<=30;$i++){ echo "<option value='$i'>" . $i ."日</option>"; } ?> </select> <br> 性别:<input type="radio" name="gender" value="1" checked> 男 <input type="radio" name="gender" value="2" > 女 <br> 请选择你的爱好:<br> <input type="checkbox" name="hobby[]" value="dance" >跳舞<br> <input type="checkbox" name="hobby[]" value="tour" >旅游<br> <input type="checkbox" name="hobby[]" value="sing" >唱歌<br> <input type="checkbox" name="hobby[]" value="dance" >打球<br> <input type="submit" value="提交"> <input type="reset" value="重填"> <br> </body> <html>