首页 > 开发 > PHP > 正文

php mysql delete数据记录删除

2024-05-04 21:59:02
字体:
来源:转载
供稿:网友

操作时点击删除连接时就会会获取到当前条目的id然后程序获取到当前id进行删除操作,至于conn.php数据库的配置文件可以自己写下,很简单这里就不再叙述了,PHP实例代码如下:

  1. <?php 
  2.        include("conn.php"); 
  3.         
  4.        $query = "select * from new order by id desc"
  5.        $res = mysql_query($query); 
  6.        while($rows =mysql_fetch_array($res)){       //将查询到结果拆到$rows数组中 
  7. ?> 
  8. <table> 
  9.        <tr> 
  10.               <td>标题:<?php echo$rows['title']?></td><td><a href="del.php?<?php $tid = $rows['id'] ?>">[删除]</a></td><td><a href="">[修改]</a></td> 
  11.        </tr> 
  12. <table> 
  13.        <?php 
  14.               } 
  15.        ?> 
  16. <form  action="addnews.php" method="post"
  17.        作者:<input type="text" name="author"/><br/><br/> 
  18.        标题:<input type="text" name="title" size="20"><br/><br/> 
  19.        内容:<textarea name="content" cols="20" rows="20"></textarea> 
  20.        <input type="submit" value="提交" name="submit"/> 
  21. </form>//开源代码Vevb.com 
  22.  
  23. //del.php代码 
  24.  
  25. <?php 
  26.        $del = "delect from test where id in ($tid)"
  27.        $res  = mysql_query($del); 
  28.        if($res){ 
  29.               echo "删除成功"
  30.        }else
  31.               echo "删除失败"
  32.        } 
  33. ?>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表