当用户选中复选框时,我无法更新mysql表。我也希望行被删除时,点击删除。我已经创建了6列动态生成有复选框。当运行时,它给出插入错误。真正的问题是从mysql表的多列中获取检查值并更新。我要存储1表示选中,存储0表示未选中。mysql表tbl\u users有3列表示用户id、email、用户密码,其他6列表示角色(web\u evaluator、reporter等)。默认值为空。
下面是我的html代码:
<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>
这里是my insert.php:
<?php
if (isset($_POST["Save"])) {
$sql=mysqli_query($DBcon,"INSERT INTO tbl_users (Web_Evaluator) VALUES
('".$_POST["doit"]."')");
if($sql){
echo "1";
}else{
echo "0";
}
}
?>
暂无答案!
目前还没有任何答案,快来回答吧!