(list.php):
<form action="del.php" method="post">
<?php
$sql="select * from news where leibie='$leibieming'";
$r=$mysqli->query($sql);
while($rs=$r->fetch_assoc()){
?>
<input type="checkbox" value="<?=$rs[id]?>" /><?=$rs[title]?>
<?php
}
?>
<input type="button" value="删除"">
</form>
2、处理惩罚页面(del.php):
<?php
if($del_id!=""){
$del_num=count($del_id);
for($i=0;$i<$del_num;$i++){
$mysqli->query("delete news.......");
}
echo("<script type='text/javascript'>alert('删除乐成!');history.back();</script>");
}else{
echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>");
}
?> 在网上抄回来的,del_id 这个变量是怎么传递的?
<input type="checkbox" value="<?=$rs[id]?>" /><?=$rs[title]?>
应为
<input type="checkbox" name="del_id[]" value="<?=$rs[id]?>" /><?=$rs[title]?>另外
if($del_id!=""){
应改写为
if(isset($_POST['del_id'])){
$del_id = $_POST['del_id'];
<input type="button" value="删除"">
改为
<input type="submit" value="删除"">
否则页面无法提交
删除的结果是 array 提示输出。
$del_id=$_POST['del_id'];
$del_num=count($del_id);
for($i=0;$i<$del_num;$i++){
$mysqli->query("delete news,newscontents from news inner join newscontents on news.Nid=newscontents.nid where news.Nid='$del_id'");
echo $del_id.'删除';
}}else{
echo("<script type='text/javascript'>alert('请先选择项目!');history.back();</script>");
}删除的执行语句。
<?php
$Name="国际新闻";
$sql="select Nid,Title from news where Class='$Name' order by Nid desc";
$csql=$mysqli->query($sql);
while($rs=$csql->fetch_assoc()){
?>
<input type="checkbox" name="del_id[]" value="<?=$rs['Nid']?>" />-<?=$rs['Nid']?>-<?=$rs['Title']?><br>
<?php
}
?>
<input type="submit" value="删除"">
</form>
echo $del_id[$i].'删除';