post传参练习-复选框表单提交

php有三种传参方法,本次练习使用post方式

制作一个有复选框的html页面,文件名:phph1.html

<!DOCTYPE html>
<html>
<head>
    <title>post传参 - php学习</title>
    <meta charset="utf-8">
</head>
<body>
    <form action="php1.php" method="post" accept-charset="utf-8"> 
    您喜欢的水果?<br /><br /> 
    <label><input name="fruit" id="fruit" type="checkbox" value="苹果" />苹果 </label> 
    <label><input name="fruit" id="fruit" type="checkbox" value="桃子" />桃子 </label> 
    <label><input name="fruit" id="fruit" type="checkbox" value="香蕉" />香蕉 </label> 
    <label><input name="fruit" id="fruit" type="checkbox" value="梨" /></label> 
    <input type="submit"value="提交"/>
    </form> 
</body>
</html>

然后开始写php代码,文件名:php1.php

<?php
    echo '你喜欢的水果是',$_POST["fruit"];
?>

随便选择一个选项(可多选),然后提交。

 然后php1.php文件将会受到传来的信息,并输出。

 新人刚学php,这篇随笔是为了记录自己学习的过程,过于粗糙低劣,大佬们勿喷

posted @ 2021-12-12 20:39  玄元一墨  阅读(250)  评论(0)    收藏  举报