form表单提交

表单:数据的提交

  action:数据提交的地址 ,默认是当前页面
  method:数据提交方式,默认是get方式
    1.get
      把数据名称和数据值用=连接,如果有多个的话,那么他会把多个数据组合用&连接,然后把数据放到url?后面传入到指定页面
    2.post
      enctype:提交的数据格式 ,默认application/x-www-form-urlencoded

1.post提交方式

HTML

<form action="post.php" method="post">
	<input type="text" name="username"/>
	<input type="text" name="age" />
	<input type="submit" value="提交"/>
</form>

PHP

<?php
header('content-type:text/html;charset="utf-8"');
error_reporting(0);

$username=$_POST['username'];
$age=$_POST['age'];

echo "你的名字:{$username},年龄:{$age}";
?>

2.get提交方式

HTML

<form action="get.php">
	<input type="text" name="username"/>
	<input type="text" name="age" />
	<input type="submit" value="提交"/>
</form>

PHP

<?php
header('content-type:text/html;charset="utf-8"');
error_reporting(0);

$username=$_GET['username'];
$age=$_GET['age'];

echo "你的名字:{$username},年龄:{$age}";
?>

  

原文地址:https://www.cnblogs.com/yangxue72/p/8178386.html