我一直试图解决这个问题,但都无济于事。我试图从表中删除多个复选框。删除功能确实有效,但它只删除最年轻id
的数据。
delete_Pm功能:
function deletePm(pmid,wrapperid,originator){
var conf = confirm(originator+"Press OK to confirm deletion of this message and its replies");
if(conf != true){
return false;
}
var ajax = ajaxObj("POST", "php_parsers/pm_system.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == "delete_ok"){
_(wrapperid).style.display = 'none';
} else {
alert(ajax.responseText);
}
}
}
ajax.send("action=delete_pm&pmid="+pmid+"&originator="+originator);
}
表的PHP代码:
$table .= '
<tr id="'.$pmid.'">
<td><center><input type="checkbox" id="cb1_'.$pmid.'" name="cb1_'.$pmid.'[]" class="cbgroup1"></center></td>
<td><a href="pm_message.php?u='.$log_username.'&pmid='.$pmid.'" onclick="markRead(\''.$pmid.'\',\''.$sender.'\')">'.$sender.'</a></td>
<td>'.$receiver.'</td>
<td>'.$subject.'</td>
<td>'.$time.'</td>
</tr>';
表格的HTML:
<table class="table table-bordered" style="margin-top: 20px;">
<thead>
<tr>
<th><center><input type="checkbox" value="" id="cbgroup1_master" onchange="togglecheckboxes(this,'cbgroup1')"></center></th>
<th>Sender</th>
<th>Receiver</th>
<th>Subject</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php echo $table; ?>
</tbody>
来自pm_system.php
的删除函数的PHP:
<?php
// Delete PM
if (isset($_POST['action']) && $_POST['action'] == "delete_pm"){
if(!isset($_POST['pmid']) || $_POST['pmid'] == ""){
mysqli_close($db);
echo "id_missing";
exit();
}
$pmid = preg_replace('#[^0-9]#', '', $_POST['pmid']);
if(!isset($_POST['originator']) || $_POST['originator'] == ""){
mysqli_close($db);
echo "originator_missing";
exit();
}
$originator = preg_replace('#[^a-z0-9]#i', '', $_POST['originator']);
// see who is deleting
if ($originator == $log_username) {
$updatedelete = mysqli_query($db, "UPDATE pm SET sdelete='1' WHERE id='$pmid' LIMIT 1");
}
if ($originator != $log_username) {
$updatedelete = mysqli_query($db, "UPDATE pm SET rdelete='1' WHERE id='$pmid' LIMIT 1");
}
mysqli_close($db);
echo "delete_ok";
exit();
}
?>