国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php mysql 刪除記錄, url傳值刪除數(shù)據(jù)

2024-05-04 21:58:28
字體:
供稿:網(wǎng)友

本款刪除數(shù)據(jù)代碼是一款根據(jù)用戶url地址欄傳過來的參數(shù),再去mysql數(shù)據(jù)庫中執(zhí)行刪除操作,PHP實(shí)例代碼如下:

  1. $host = 'localhost'
  2. $user_name = 'root'
  3. $password = 'admin'
  4.  
  5. $conn = mysql_connect($host,$user_name,$password); 
  6. if(!$conn
  7.     die('數(shù)據(jù)庫連接失敗:'.mysql_error()); 
  8. mysql_select_db('test'); 
  9.  
  10. $sql = 'select id,name,city,created_time from users'
  11.  
  12. $result = mysql_query($sqlor die("<br/>error: <b>".mysql_error()."</b><br/>產(chǎn)生問題的sql:".$sql); 
  13. ?> 
  14. <html> 
  15. <head> 
  16. <title>13-12.php</title> 
  17. <script language="網(wǎng)頁特效"
  18.  
  19. </script> 
  20. </head> 
  21. <center> 
  22.  
  23. <body> 
  24. <table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7b7b84"
  25.     <tr bgcolor="#8bbcc7">  
  26.         <td height="33"><div align="center"><strong>用戶id</strong></div></td> 
  27.         <td><div align="center"><strong>用戶名稱</strong></div></td> 
  28.         <td><div align="center"><strong>來自城市</strong></div></td> 
  29.         <td><div align="center"><strong>注冊(cè)時(shí)間</strong></div></td> 
  30.         <td><div align="center"><strong>操作</strong></div></td> 
  31.     </tr> 
  32.  
  33. <?php 
  34. if($num = mysql_num_rows($result)) 
  35.     while($row = mysql_fetch_array($result,mysql_assoc)) 
  36.     { 
  37. ?> 
  38.     <tr bgcolor="#ffffff">  
  39.         <td height="22" align="right"><?php echo $row['id']; ?>&nbsp;</td> 
  40.         <td height="22">&nbsp;<?php echo $row['name']; ?>&nbsp;</td> 
  41.         <td height="22">&nbsp;<?php echo $row['city']; ?>&nbsp;</td> 
  42.         <td height="22">&nbsp;<?php echo $row['created_time']; ?>&nbsp;</td> 
  43.         <td height="22">&nbsp;<a onclick="javascript:if(confirm('確定要?jiǎng)h除用戶信息嗎?')) return true; else return false;" href="13-13.php?id=<?php echo $row['id']; ?>">刪除</a>&nbsp;</td> 
  44.     </tr> 
  45. <?php 
  46.     } 
  47. mysql_close($conn); 
  48. ?> 
  49.  
  50. </table> 
  51. </body> 
  52. </center> 
  53. </html> 
  54.  
  55. <?php 
  56. if(!isset($_get['id'])) 
  57.     echo '參數(shù)錯(cuò)誤!'
  58.     exit
  59.  
  60. $id = $_get['id']; 
  61. if(emptyempty($id)) 
  62.     echo '用戶id不能為空!'
  63.     exit
  64.  
  65. $host = 'localhost'
  66. $user_name = 'root'
  67. $password = 'admin'
  68.  
  69. $conn = mysql_connect($host,$user_name,$password); 
  70. if(!$conn
  71.     die('數(shù)據(jù)庫連接失敗:'.mysql_error()); 
  72. mysql_select_db('test'); 
  73.  
  74. //先判斷是否存在該id的用戶 
  75. $sql = "select * from users where id=$id"
  76. $result = mysql_query($sqlor die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql); 
  77. if(!mysql_num_rows($result)) 
  78.     echo '用戶id錯(cuò)誤!'
  79.     exit
  80.  
  81. //刪除用戶數(shù)據(jù)//開源代碼Vevb.com 
  82. $sql = "delete from users where id=$id"
  83. mysql_query($sqlor die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql); 
  84. mysql_close($conn); 
  85.  
  86. echo '數(shù)據(jù)刪除成功,返回<a href="13-12.php">13-12.php</a>查看數(shù)據(jù)'

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 怀远县| 满城县| 玉林市| 安多县| 阿合奇县| 璧山县| 安乡县| 霍州市| 瑞金市| 郑州市| 石柱| 肇东市| 浮梁县| 涿鹿县| 赤水市| 嘉黎县| 镇远县| 海阳市| 历史| 永定县| 咸丰县| 华蓥市| 东乌| 榆社县| 莱芜市| 昭觉县| 宜兰市| 运城市| 天祝| 澎湖县| 武宁县| 武清区| 寻甸| 柳江县| 荣成市| 东方市| 津南区| 山东| 凤凰县| 武山县| 成武县|