简体   繁体   English

使用 html 开关复选框 php if 语句更新数据库

[英]Update database with html Switch Checkbox php if statement

Hope someone help sort this for me, even if its another solution, as I have hit the php brick wall希望有人帮我解决这个问题,即使它是另一种解决方案,因为我遇到了 php 砖墙

I have a form with a checkbox switch in it我有一个带有复选框开关的表单

                       <div class="col-md-3">
                        <input type="hidden" name="needclean" value="No" checked />
                        <div class="switch">
                        <label>NO<input type="checkbox" name="needclean" value="Yes"><span class="lever switch-col-green"></span>YES</label>
                        </div>
                        </div>

What I want to happen is when the user clicks "Yes" it populates the cell in the DB called "Status" to "Needs Cleaning" and if the user Clicks "No" it populates the "Status" cell in the DB to "Good to Go"我想要发生的是,当用户单击“是”时,它将数据库中名为“状态”的单元格填充为“需要清洁”,如果用户单击“否”,它将数据库中的“状态”单元格填充为“好”去”

I have tried this我试过这个

<?php
                    if(isset($_POST['needclean'])){
                    $clean = $_POST['needclean'];
                }
                if(isset($needclean) == "Yes"){ 
                    echo '<input type="hidden" name="status" value="Needs Cleaning" />';
                } else {
                     echo '<input type="hidden" name="status" value="Good to Go" />';
                }

                    ?>

But all it does is populate the "Status" cell with "Good to go" no matter if I select Yes or No但它所做的只是用“Good to go”填充“状态”单元格,无论我是 select 是还是否

I hope I have explained this and if you need any more info please let me know我希望我已经解释了这一点,如果您需要更多信息,请告诉我

Thanks in advance for any help提前感谢您的帮助

Remove the input type hidded, do this:删除隐藏的输入类型,执行以下操作:

if(isset($_POST['needclean']) { echo  "is checked";} else { echo "Not checked";}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM