Home >Backend Development >PHP Tutorial >Summary of PHP get form methods_PHP tutorial

Summary of PHP get form methods_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:59873browse

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.

The $_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[&#39;login&#39;]);&#160;&#160; //输出帐号
echo("<br>");
echo("你的姓名是:" .$_POST[&#39;yourname&#39;] );&#160;&#160; //输出姓名
echo( "<br>");

echo("你的密码是:" . $_POST[&#39;passwd&#39;]&#160;&#160; );&#160;&#160; //输出密码
echo("<br>");

echo("你的查询密码问题是:" . $_POST[&#39;question&#39;]&#160;&#160; );&#160;&#160; //查询密码问题
echo("<br>");

echo("你的查询密码答案是:" . $_POST[&#39;question2&#39;]&#160;&#160;&#160; );&#160;&#160; //查询密码答案
echo("<br>");

echo("你的出生日期是:" . $_POST[&#39;byear&#39;] ."年". $_POST[&#39;bmonth&#39;] . "月" . $_POST[&#39;bday&#39;] . "日"&#160;&#160;&#160; );&#160;&#160; //出生日期
echo("<br>");


echo("你的性别是:" . $_POST[&#39;gender&#39;]);&#160;&#160; //性别
echo("<br>");


echo("你的爱好是:<br>"&#160;&#160; );&#160;&#160; //爱好
foreach ($_POST[&#39;hobby&#39;] as $hobby)&#160;{
&#160;&#160; echo($hobby . "<br>");
}

?>&#160;
&#160;
相应的表单代码如下:

<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>

出生日期:
&#160;&#160; <select name="byear" id="BirthYear" tabindex=8>
&#160;&#160;&#160;&#160; <?php
&#160;&#160;for($i=1930;$i<=2009;$i++){
&#160;&#160;echo "<option value=&#39;$i&#39;>" . $i ."年</option>";
&#160;&#160;}
&#160; ?>
&#160;&#160; </select>
&#160;&#160;&#160;&#160; <select name="bmonth" id="BirthYear" tabindex=8>
&#160;&#160;&#160;&#160; <?php
&#160;&#160;for($i=1;$i<=12;$i++){
&#160;&#160;echo "<option value=&#39;$i&#39;>" . $i ."月</option>";
&#160;&#160;}
&#160; ?>
&#160;&#160; </select>
&#160;&#160;&#160;&#160; <select name="bday" id="BirthYear" tabindex=8>
&#160;&#160;&#160;&#160; <?php
&#160;&#160;for($i=1;$i<=30;$i++){
&#160;&#160;echo "<option value=&#39;$i&#39;>" . $i ."日</option>";
&#160;&#160;}
&#160; ?>
&#160;&#160; </select>
<br>
性别:<input type="radio" name="gender" value="1" checked>
&#160;&#160;&#160;&#160;&#160;&#160; 男
&#160;&#160;&#160;&#160;&#160;&#160; <input type="radio" name="gender" value="2" >
&#160;&#160;&#160;&#160;&#160;&#160; 女
<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"&#160;&#160; value="提交">
<input type="reset"&#160;&#160; value="重填">
<br>
</body>
<html>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/820632.htmlTechArticleWhen php accepts information submitted through the HTML form, it will save the submitted data in the global array, we can call System-specific array of automatic global variables to obtain these. Commonly used automatic...
Statement:
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