Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 我想根据其他复选框值更新数据库中的复选框值_Php_Jquery_Mysql - Fatal编程技术网

Php 我想根据其他复选框值更新数据库中的复选框值

Php 我想根据其他复选框值更新数据库中的复选框值,php,jquery,mysql,Php,Jquery,Mysql,我想根据其他复选框值问题将我的复选框值更新到数据库中,如果我选中了8个复选框8个复选框值插入状态为“是”的复选框值再次未选中状态为“否”的复选框我的问题是,如果我取消选中一个复选框,状态将更改,但以前的复选框值将再次插入。我希望随着时间的推移更新这些复选框值。请让我解决此问题。我希望根据另一个复选框值更新我已选中的复选框值 <script> $("input[type=checkbox]").on("change", function () { var ids =

我想根据其他复选框值问题将我的复选框值更新到数据库中,如果我选中了8个复选框8个复选框值插入状态为“是”的复选框值再次未选中状态为“否”的复选框我的问题是,如果我取消选中一个复选框,状态将更改,但以前的复选框值将再次插入。我希望随着时间的推移更新这些复选框值。请让我解决此问题。我希望根据另一个复选框值更新我已选中的复选框值

<script>
 $("input[type=checkbox]").on("change", function () {
        var ids = [];
        var dis = [];
        $('input[type=checkbox]:checked').each(function () {
            ids.push($(this).val());
        });
        $('input[type=checkbox]:not(:checked)').each(function(){
            dis.push($(this).val());
            });
            dis=dis.toString();
           ids=ids.toString();
        $.ajax({
            url: "bodcheckbox.php",
            type: "POST",
            async: true,
            cache: false,
            data: ({value: ids,
                      unchecked:dis,
                      }),
            dataType: "text",
            success: function (data) {
             alert("activitysubmitted");
            }
        });
    }); 

 </script>  
<?php
session_start();
include'config.php';
$username=$_SESSION['username'];

//if(isset($_POST['value']))
//{
 //unchecked box value--
$unchecked=$_POST['unchecked'];
$uncheckboxvalue=array();
$uncheckboxvalue=explode(",",$unchecked);
//--checkedbox value--
$checkbox=array();
$checklist=$_POST['value'];
$checkbox=explode(",",$checklist);
$currentdate = date('d-m-Y');
$year = date('Y', strtotime($currentdate));

$month = date('F', strtotime($currentdate));
$date=date('d',strtotime($currentdate));
date_default_timezone_set('Asia/Kolkata');
$currenttime=date("h-i-sa");
if(!empty($checklist)&& empty($unchecked))
{
 foreach($checkbox as $check)
     {
    $bod_insert=mysql_query("insert into bod(username,activityname,tickeddate,tickedtime,status)values('$username','".mysql_real_escape_string(      $check)."','$date-$month-$year','$currenttime','yes')",$conn);
     }
     foreach($uncheckboxvalue as $uncheck)
     {
      $bod_update=mysql_query("update bod set status='no' where activityname='".mysql_real_escape_string( $uncheck)."' and username='$username'",$conn);
     }
}

else    
{
    foreach($checbox as $check)
    {
    $bod_update=mysql_query("update bod set status='yes' tickedtime='$currenttime',tickeddate='$date-$month-$year' where activityname=''".        mysql_real_escape_string( $check)."'",$conn);
    }
    foreach($uncheckboxvalue as $uncheck)
     {
      $bod_update=mysql_query("update bod set status='no' where activityname='".mysql_real_escape_string( $uncheck)."' and username='$username'",$conn);
     }
}
?>

$(“输入[type=checkbox]”)。在(“更改”上,函数(){
var-id=[];
var dis=[];
$('input[type=checkbox]:选中')。每个(函数(){
id.push($(this.val());
});
$('input[type=checkbox]:未(:选中)')。每个(函数(){
dis.push($(this.val());
});
dis=dis.toString();
ids=ids.toString();
$.ajax({
url:“bodcheckbox.php”,
类型:“POST”,
async:true,
cache:false,
数据:({value:ids,
未选中:dis,
}),
数据类型:“文本”,
成功:功能(数据){
警报(“活动已提交”);
}
});
}); 

复选框只张贴如果他们被选中如果取消选中他们不张贴没有格特看我的代码我可以得到我的值未选中复选框值。我的问题是,当我取消选中特定收件箱时,我不想插入以前选中的复选框值,而是我必须更新这些复选框值。你不能更新这些复选框值,因为html不会发布未选中的框,你必须添加另一个输入,然后在php中进行比较,如果框2未选中$\u post[“框2”]will=null未选中,数组将被弄乱。请使用单选按钮并隐藏一个,然后比较是否在php中同时选择或仅选择1个。谢谢。我从您的宝贵评论中了解到一些想法,但我必须在任务中使用复选框