简单的php获取表单数据

1$_SERVER['PHP_SELF']表示:当前执行脚本的文件名例如,在地址为
 http://example.com/test.php/foo.bar 的脚本中使用
 $_SERVER['PHP_SELF'] 将得到 /test.php/foo.bar。
2、PHP $_POST
PHP $_POST 被广泛应用于收集表单数据,在HTML form标签的指定该属性:
"method="post"。以下实例显示了一个输入字段(input)及提交按钮(submit)
的表单(form)。当用户通过点击 "Submit" 按钮提交表单数据时, 表单数据将发
送至<form>标签中action 属性中指定的脚本文件。 在这个实例中,我们指定当前
文件来处理表单数据。如果你希望其他的PHP文件来处理该数据,你可以修改该指
定的脚本文件名。然后,我们可以使用超级全局变量 $_POST 来收集表单中的
input 字段数据:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
名字: <input type="text" name="fname">
年龄: <input type="text" name="age">
<input type="submit" value="提交">
</form>

<?php 
$name = $_REQUEST['fname'];
echo $name;
echo "<br/>";
$age = $_REQUEST['age'];   
echo $age;
?>        

</body> 

</html>

猜你喜欢

转载自blog.csdn.net/zwhsoul/article/details/80100431