Home  >  Article  >  Backend Development  >  html - php checkbox $_post is all on when it comes out

html - php checkbox $_post is all on when it comes out

WBOY
WBOYOriginal
2016-08-04 09:21:271368browse

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>

Reply content:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn