php和表单(1)

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

<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这两个超级全局变量来获取前端发送来的数据,同时它们是一个html

关联数组,咱们能够遍历获取所有数据(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"]; ?>
相关文章
相关标签/搜索