我写了检查所有并删除但是当我点击删除表单提交但复选框的值未发布
我的html代码如下:
<?php
$sql="select * from tbl_comment order by id desc limit $start,$rec_per_page";
$result = $db->sql_query($sql);
?>
<br>
<form action="?page=<?=$_REQUEST['page']?>&op=delete" method="post" name="email">
<table border=0 cellpadding=5 width="100%" cellspacing=0>
<tr class="text1">
<td colspan=3 class="darkBlue"><B>Comment List</B></td>
</tr>
<tr bgcolor="#CACBD2" class="text1">
<td class="text1"><B>Name</B></td>
<td class="text1"><B>Comment</B></td>
<td class="text1"><strong>Action </strong></td>
</tr>
<?php
$r1=0;
$class='white';
while($rec=$db->sql_fetchrow($result))
{
$status = $rec['status'];
if($status==1)
$activelink = '<a href="index.php?page='.$page.'&comment_id='.$rec['id'].'&op=status&flag=disapprove&page_em='.$page_em.'" onclick="return confirm(\'Do you want to disapprove?\')">Disapprove</a>';
else
$activelink = '<a href="index.php?page='.$page.'&comment_id='.$rec['id'].'&op=status&flag=approve&page_em='.$page_em.'" onclick="return confirm(\'Do you want to Approve?\')">Approve</a>';
?>
<tr class="<?= $class;?>">
<td><?=$rec['fname'].$rec['lname']?></td>
<td><?=$rec['comment']?></td>
<td><!--<a href="index.php?page=<?=$page?>&comment_id=<?=$rec['id']?>&op=delete" onclick="return confirm('Do you want to Delete?')">[X]</a>--><input type="checkbox" name="chkdelete[]" id="chkdelete[]" value="<?=$rec['id']?>" /><?=$rec['id']?> | <?=$activelink?></td>
</tr>
<?php
if($class=='white')
$class='lightBlue';
else
$class='white';
}
for($pages = 1; $pages <= $total_pages; $pages++)
{
if ($pages == $page_em)
{
$nav .= "<strong style='font-size:12px;' class='redbold'>".$pages."</strong> ";
}
else
{
$nav .= "<a href=\"?page_em=".$pages."&page=comments\">".$pages."</a> ";
}
}
if ($total_pages > 1)
{
if (($page_em-1) > 0) {
$prev= "<a href=\"?page_em=".($page_em-1)."&page=comments\">Previous</a> ";
} else {
$prev= "Previous ";
}
$content .= " ";
if (($page_em+1) <= $total_pages) {
$next.= "<a href=\"?page_em=".($page_em+1)."&page=comments\">Next</a>";
} else {
$next= "Next";
}
}
$NavigationButton=$prev.$nav.$next;
if($total_rec==0){
$NavigationButton="Record not found!";
}
?>
<tR class="text1">
<td ><?=$NavigationButton?></td>
<td></td>
<td align="left">
<strong>
<input type="checkbox" name="All" id="All" value="yes" onclick="javascript:checkall();"/> (Select All) |
<label>
<input type="submit" name="Submit" value="Delete Selected" onclick="return confirm('Do you want to Delete?')"/>
</label>
</strong>
</td>
</tr>
</table>
</form>
<?php
}
要删除的功能如下:
function delete_email()
{
print_r($ids = $_POST['chkdelete']);
foreach($ids as $key=>$id)
{
echo "hi2"; die;
global $db;
//$email=$_GET['comment_id'];
$sql="delete from tbl_comment where id='".$id."'";
$db->sql_query($sql);
echo "deleted comments".$id;
}
//$url="index.php?page=".$page;
//header("Location:".$url);
}
任何人都请帮助我
答案 0 :(得分:0)
据我所知,您的复选框名称表示chkdelete[]
,而您引用的是POST变量chkdelete
(不带[])。
答案 1 :(得分:0)
<form action="?page=<?=$_REQUEST['page']?>&op=delete" ...
您是否正在使用此表单操作执行正确的功能?另外,如果你在这个网址上做了一些重定向,你的$ _POST数据将会丢失(另一个请求,没有发布数据)。
不应该与您的问题有任何关系,但是值得注意的是,您正在为所有复选框分配相同的DOM ID('chkdelete []'),而它应该是unqe。