In the following code, the result of echo $_POST['hobbyS']; is on. Why is this? How can I make it return the correct result?
<code><html> <?php $hobby = array('跑步','游泳','篮球','足球'); ?> <body> <form method='post'> <p>姓名:<input type='text' name="name"></p> <p>爱好: <?php foreach($hobby as $v){ echo "<input type='checkbox' name='hobbyS'/>".$v; } ?> </p> <input type="submit" value='提交'/> <input type="reset" value='重置' /> </form> <?php if(!empty($_POST)){ ECHO $_POST['name']; echo $_POST['hobbyS']; } ?> </body> </html> </code>
In the following code, the result of echo $_POST['hobbyS']; is on. Why is this? How can I make it return the correct result?
<code><html> <?php $hobby = array('跑步','游泳','篮球','足球'); ?> <body> <form method='post'> <p>姓名:<input type='text' name="name"></p> <p>爱好: <?php foreach($hobby as $v){ echo "<input type='checkbox' name='hobbyS'/>".$v; } ?> </p> <input type="submit" value='提交'/> <input type="reset" value='重置' /> </form> <?php if(!empty($_POST)){ ECHO $_POST['name']; echo $_POST['hobbyS']; } ?> </body> </html> </code>
When the checkbox is checked, the default value is on. After setting the value, the checkbox is the value of value
chexkbox plus value=1
http://www.111cn.net/phper/php/37172.htm
Please take a look at the examples in this, there are very detailed explanations!