我想根据其他复选框值

时间:2017-04-21 09:39:35

标签: php jquery mysql

我想根据其他复选框值问题将我的复选框值更新到数据库中如果我选中了8个复选框,则会插入8个复选框值,状态='是'再次取消选中一个状态=' no'我的问题是,如果我取消选中一个复选框状态已更改,但以前的复选框值再次插入我想更新那些复选框值与time.get我over this.i想要更新我已检查的复选框值基于另一个复选框值...

<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);
     }
}
?>

0 个答案:

没有答案