php和表单(1)

先来一段处理表单的html代码(test.html)

<form action="index.php" method="post">
    name : <input type="text" name="name">
    e-mail : <input type="text" name="email">
    <input type="submit">
</form>

当点击submit就可以向后端传输数据了,在这里是通过post的方式进行传输滴,也可以通过get的方式。后端通过$_POST和$_GET这两个超级全局变量来获取前端发送来的数据,同时它们是一个

关联数组,我们可以遍历获取全部数据(index.php),如下

<?php 
foreach($_POST as $key => $value){
    echo $key . ":" . $value . "<br>";
}
?>
//name:复读机
//email:000000@qq.om

也可以获取制定name的值(index.php),如下:

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

 

posted on 2015-05-10 15:56  复读机  阅读(72)  评论(0编辑  收藏  举报

导航