Home  >  Article  >  Backend Development  >  php form submission example code

php form submission example code

怪我咯
怪我咯Original
2017-07-13 14:42:496879browse

When

php accepts information submitted through the HTML form, it will save the submitted data in the 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 "user" is submitted using the GET method, you can use

$_GET["user"] or $_GET['user']

Example code

register.php:

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=gb2312"> 
<title>注册页面</title> 
</head> 
<body> 
<form action="request.php" method="post" name="registForm"> 
<table width="330" border="0" align="center" cellpadding="5" bgcolor="#eeeeee"> 
<tr> 
<td width="40%">用户名:</td> 
<td><input name="username" type="text" id="username"/></td> 
</tr> 
<tr> 
<td>姓名:</td> 
<td><input name="name" type="text" id="name"/></td> 
</tr> 
<tr> 
<td>密码:</td> 
<td><input name="pwd" type="text" id="pwd"/></td> 
</tr> 
<tr> 
<td>邮箱:</td> 
<td><input name="email" type="text" id="email"/></td> 
</tr> 
<tr> 
<td colspan="2" align="center"> 
<input type="submit" value="提交" name="submit"/> 
<input type="reset" value="重置" name="button"/> 
</td> 
</tr> 
</table> 
</form> 
</body> 
</html>

request.php

<?php 
$username = $_POST[&#39;username&#39;]; 
$name = $_POST[&#39;name&#39;]; 
$pwd = $_POST[&#39;pwd&#39;]; 
$email = $_POST[&#39;email&#39;]; 
//print_r($username); 
if(!empty($username)) 
{ 
echo "您填写的信息为:<br>\n"; 
echo "用户名: $username <br>\n"; 
echo "姓名: $name <br>\n"; 
echo "密码: $pwd <br>\n"; 
echo "邮箱: $email <br>\n"; 
} 
print_r($_POST) 
//echo "aaaa"; 
?> 

The above is the detailed content of php form submission example code. For more information, please follow other related articles on the PHP Chinese website!

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