Home  >  Article  >  Backend Development  >  How to get form submitted data in PHP

How to get form submitted data in PHP

(*-*)浩
(*-*)浩Original
2019-09-20 11:37:105023browse

How PHP gets the data submitted by the form

How to get form submitted data in PHP

##1. Super global array variable: $_GET[]

Description: Get the data submitted by form method = “get”

Example: $username = $_GET[“username”];

2. Super global array variable: $_POST[] (Recommended learning: PHP programming from entry to proficiency)

Description: Get form method = "post" Submit Data

Example: $username = $_POST[“username”];

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META name="Generator" content="EditPlus">
  <META name="Author" content="">
  <META name="Keywords" content="">
  <META name="Description" content="">
  <style type="text/css">
  </style>
  <script type="text/javascript">
  </script>
 </HEAD>
 
 <BODY>
  <?php
  var_dump($_POST);  //超全局变量,$_GET  $POST  (数组类型)
if(isset($_POST["ac"]) && $_POST["ac"]=="login")  //防止灌水,判断表单确实是自己的表单
{
	$username=$_POST["username"];
	$userpwd=$_POST["userpwd"];
	echo("用户名是:{$username},密码是:{$userpwd}");
}
  ?>
 
  <form name="form1" method="post" action="">
用户名:<input type="text" name="username" />
密码:<input type="password" name="userpwd" />
<input type="hidden" name="ac" value="login" />
<input type="submit" value="提交表单" />
  </form>
 </BODY>
</HTML>

The above is the detailed content of How to get form submitted data in PHP. 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