我有一个 HTML 表单,其中包含一些记录。应通过选择一个或所有记录对应的复选框来删除记录。
当我选中一条记录的复选框并单击删除时,查询成功运行,但记录没有删除。
这是PHP代码:
if(isset($_POST['delete']))
{
$allCheckBoxId = $_POST['chkDel'];
array_map ('mysql_real_escape_string', $allCheckBoxId);
$ids = implode(",", $allCheckBoxId);
$object=new connection();
$object=$object->dbConnect();
$st=$object->prepare(
"delete * from banners where bannerid IN (?)");
$st->bindParam(1, $ids);
$delete=$st;
$delete->execute();
if($delete)
{
echo "record deleted successfully." .
"This will go to banners within 5 sec";
}
else
{
echo "not deleted";
}
}
和 HTML 表单:
<form name="myform" action="listbanners.php" method="post" OnSubmit="return onDelete();" id="frm1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="13"><input type="checkbox" class="checkbox" title="select all" onclick="checkAll(document.myform.chkDel);" name="CheckAll" /></th>
<th width="13">ID</th>
<th>Name</th>
<th><input type="submit" name="delete" value"Delete"></th>
</tr>
<?php
$object=new connection();
$object=$object->dbConnect();
$st=$object->prepare("select * from banners order by bannerid desc");
$st->execute();
while($row=$st->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><input name="chkDel[]" type="checkbox" title="select" class="checkbox" value="<?php echo $row['bannerid'];?>"/></td>
<td><?php echo $row['bannerid'];?></td>
<td><h3 onClick="location='editbanner.php?bannerid=<?php echo $row['bannerid'];?>'"><?php echo $row['file'];?></h3></td>
<td><input type="submit" name="delete" value="delete"/></td>
</tr>
</form>