表单数据的提交
action : 数据提交的地址,默认是当前页面
method : 数据提交的方式,默认是get方式
post:
把数据名称和数据值用=连接,如果有多个的话,那么他会把多个数据组合用&进行连接,然后把数据放到url?后面传到指定页面
enctype : 提交的数据格式,默认application/x-www-form-urlencoded
<body>
<form action="links/1.post.php" method="post">
<input type="text" name="username" placeholder="输入名字" />
<input type="text" name="age" placeholder="输入年龄" />
<input type="submit" class="myBtn" value="提交" />
</form>
</body>
post与get的区别只在于书写名字和enctype的区别,post必须添加enctype类型,而get用默认的即可,同时get请求的数据量小且安全性低,数据内容暴露在url后面的链接里面,而post则可通过发送参数来传递,高效。
<?php
header('content-type:text/html;charset="utf-8"');
error_reporting(0);
//$_REQUEST
$username = $_POST['username'];
$age = $_POST['age'];
echo "你的名字:{$username},年龄:{$age}";
?>