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

WBOY
Release: 2016-08-04 09:21:27
Original
1366 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!