Home >Backend Development >PHP Tutorial >批量删除文章ID?

批量删除文章ID?

WBOY
WBOYOriginal
2016-06-23 14:10:511272browse

(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 这个变量是怎么传递的?


回复讨论(解决方案)

你抄漏了!
" />=$rs[title]?>
应为
" />=$rs[title]?>

另外
if($del_id!=""){
应改写为
if(isset($_POST['del_id'])){
  $del_id = $_POST['del_id'];

还有

改为

否则页面无法提交

你抄漏了!
" />=$rs[title]?>
应为
" />=$rs[title]?>

另外
if($del_id!=""){
应改写为
if(isset($_POST['del_id'])){
  $del_id = $_POST['del_id'];

删除的结果是  array 提示输出。

还有

改为

否则页面无法提交

修正了。

贴出你修改后的 php 代码

if(isset($_POST['del_id'])){    $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>");}


删除的执行语句。

<form action="delAllZhangJie.php"method="post"><?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>

贴出你修改后的 php 代码

帮我看看是哪的问题咯

$mysqli->query("delete news,newscontents from news inner join newscontents on news.Nid=newscontents.nid where news.Nid='$del_id[$i]'");
        echo $del_id[$i].'删除';

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn