多列中的多个复选框

时间:2018-08-19 19:35:14

标签: mysql

当用户选中复选框时,我无法更新mysql表。我也希望在单击删除时删除行。我已经创建了6列动态生成的具有复选框的列。运行时会提示插入错误。真正的问题是要从多个列中获取检查值并在mysql表的多个列中进行更新。我想将1存储为选中状态,将0存储为未选中状态。 mysql表tbl_users有3列分别用于user_id,email,user_password和其他6个角色(Web_Evaluator,Reporter等)。默认值为空。

这是我的html代码:

^         # Begin of line
  \s*     # 0 or more spaces (this can be deleted if the line does not start with space)
  [^:\n]+ # Any non-':',EOL character repeated one or more times
  :       # ':' character. Remove if you don't want this

这是我的insert.php:

<head>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
    $("#Save").on('click',function(){
        var pro_lan= [];
        $.each($('input[name="p_lan"]:checked'),function(){
            pro_lan.push($(this).val());
        });
        var all_pro_lan=pro_lan.join(", ");
        $.ajax({
            type: 'post',
            url: 'insert.php',
            data:{doit:all_pro_lan},
            success:function(data){
                if(data==1){
                    alert("Insert Success");
                }else{
                    alert("Insert Error!!");
                }
            }
        });
    });
});
</script>
</head>
<body>
<button class="button1" style="float:right" name="Save" 
id="Save">Save</button>;

<table id="example" class="table table-striped table-bordered" 
cellspacing="0" style="width:50%;">

<thead>
        <tr>
            <th >Blocker Name</th>
            <th>Email Address</th>
            <th style="text-align:center" title="Blocker Type">Web 
Evaluator</th>
            <th style="text-align:center" title="Blocker Type">Forensic 
Researcher</th>
            <th style="text-align:center" title="Blocker Type">Quality 
Control Scholar</th>
            <th style="text-align:center" title="Blocker Type">Eportal 
Maintainer</th>
            <th style="text-align:center" title="Blocker Type">Reporter</th>
            <th style="text-align:center" title="Blocker Type">Quality 
Assurance Scholar</th>
            <th style="text-align:center" title="Blocker Type">Delete 
Blocker</th>
        </tr>
    </thead>
    <tbody>

<?php

$result = $DBcon->query($sql);
$id=$row['user_id']; 

if ($result->num_rows > 0) 
{
//Output data of each row
while($row = $result->fetch_assoc()) 
    {

 $strChecked1="";$strChecked2="";$strChecked3="";
 $strChecked4="";$strChecked5="";$strChecked6="";

    $id=$row['user_id'];

    if ($row['Web_Evaluator'] == "1")
        $strChecked1 = "checked='checked'";

    if ($row['Forensic_Researcher'] == "1")
        $strChecked2 = "checked='checked'";

    if ($row['Quality_Control_Scholar'] == "1")
        $strChecked3 = "checked='checked'";

    if ($row['Eportal_Maintainer'] == "1")
        $strChecked4 = "checked='checked'";

    if ($row['Reporter'] == "1")
        $strChecked5 = "checked='checked'";    

    if ($row['Reporter Quality_Assurance_Scholar'] == "1")
        $strChecked6 = "checked='checked'";    

    echo 

    "<tr><td>"
    .$row["username"].

    "</td><td>"
    .$row["email"].


   "</td>"
    .'<td style="text-align:center;"><input class="assign1" name="p_lan" 
id="p_lan" value="nnnnn" type="checkbox"'. $strChecked1 .' '.


    "</td>"
    .'<td style="text-align:center;"><input class="assign2" name="home['. 
$row["user_id"].']" id="home['. $row["user_id"].']"  value="'.$id.'"   type="checkbox"'. $strChecked2 .' '.

    "</td>"
    .'<td style="text-align:center;"><input class="assign3" name="assign3[]" 
id="add_driver'.$id.'" value="'.$id.'"   type="checkbox"'. $strChecked3 .' 
'.

    "</td>"
    .'<td style="text-align:center;"><input class="assign4" name="assign4[]" 
id="add_driver'.$id.'" value="'.$id.'"   type="checkbox"'. $strChecked4 .' 
'.

    "</td>"
    .'<td style="text-align:center;"><input class="assign5" name="assign5[]" 
id="add_driver'.$id.'" value="'.$id.'"   type="checkbox"'. $strChecked5 .' 
'.

    "</td>"
    .'<td style="text-align:center;"><input class="assign6" name="assign6[]" 
 id="add_driver'.$id.'" value="'.$id.'"   type="checkbox"'. $strChecked6 .' 
'.

    "</td>"
    .'<td ><input type="image" id="Delete" name="Delete" title="Delete User" 
 Text="Delete" src="Pix/Delete.png" style="width:25px; height:25px; margin- 
left: 15px; " /> '.
    "</td></tr>"
    ;

   }

}

else 
{
echo "0 results";
}

$DBcon->close();
?>
         </tbody>
</table>
</div>
</body>

0 个答案:

没有答案