Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP更新chekbox值_Php_Mysql_Codeigniter_Checkbox - Fatal编程技术网

使用PHP更新chekbox值

使用PHP更新chekbox值,php,mysql,codeigniter,checkbox,Php,Mysql,Codeigniter,Checkbox,我需要使用复选框,如果用户选中了复选框,则复选框的值保存为1,如果未选中,则值存储为0 此代码有效 //add <input type='hidden' name='status' value='0'/> <input type='checkbox' name='status' value='1' <?php echo (isset($_POST['status']))?'checked':'';?>/> //添加 /> 直到现在它还在工作 但当用户试图

我需要使用复选框,如果用户选中了复选框,则复选框的值保存为1,如果未选中,则值存储为0

此代码有效

//add 
<input type='hidden' name='status' value='0'/>
<input type='checkbox' name='status' value='1' <?php echo (isset($_POST['status']))?'checked':'';?>/>
//添加
/>
直到现在它还在工作


但当用户试图编辑此复选框时,以前的值将存储在DB中,而不是新的值。

好吧,您给我们看一些代码,因为只有这些代码,帮助就很小。@Naruto我已经发布了代码,要求是我无法更新复选框值我没有看到任何相关的数据代码写入数据库,这就是你的问题。@Naruto得到了答案。你有2个
状态
命名字段,因为隐藏的
//edit
<input type="checkbox" name="status" value="1"  <?php echo ($row['status'] == 1) ? 'checked="checked"' : ''; ?>/>