本款刪除數(shù)據(jù)代碼是一款根據(jù)用戶url地址欄傳過來的參數(shù),再去mysql數(shù)據(jù)庫中執(zhí)行刪除操作,PHP實(shí)例代碼如下:
- $host = 'localhost';
- $user_name = 'root';
- $password = 'admin';
- $conn = mysql_connect($host,$user_name,$password);
- if(!$conn)
- {
- die('數(shù)據(jù)庫連接失敗:'.mysql_error());
- }
- mysql_select_db('test');
- $sql = 'select id,name,city,created_time from users';
- $result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>產(chǎn)生問題的sql:".$sql);
- ?>
- <html>
- <head>
- <title>13-12.php</title>
- <script language="網(wǎng)頁特效">
- </script>
- </head>
- <center>
- <body>
- <table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7b7b84">
- <tr bgcolor="#8bbcc7">
- <td height="33"><div align="center"><strong>用戶id</strong></div></td>
- <td><div align="center"><strong>用戶名稱</strong></div></td>
- <td><div align="center"><strong>來自城市</strong></div></td>
- <td><div align="center"><strong>注冊(cè)時(shí)間</strong></div></td>
- <td><div align="center"><strong>操作</strong></div></td>
- </tr>
- <?php
- if($num = mysql_num_rows($result))
- {
- while($row = mysql_fetch_array($result,mysql_assoc))
- {
- ?>
- <tr bgcolor="#ffffff">
- <td height="22" align="right"><?php echo $row['id']; ?> </td>
- <td height="22"> <?php echo $row['name']; ?> </td>
- <td height="22"> <?php echo $row['city']; ?> </td>
- <td height="22"> <?php echo $row['created_time']; ?> </td>
- <td height="22"> <a onclick="javascript:if(confirm('確定要?jiǎng)h除用戶信息嗎?')) return true; else return false;" href="13-13.php?id=<?php echo $row['id']; ?>">刪除</a> </td>
- </tr>
- <?php
- }
- }
- mysql_close($conn);
- ?>
- </table>
- </body>
- </center>
- </html>
- <?php
- if(!isset($_get['id']))
- {
- echo '參數(shù)錯(cuò)誤!';
- exit;
- }
- $id = $_get['id'];
- if(emptyempty($id))
- {
- echo '用戶id不能為空!';
- exit;
- }
- $host = 'localhost';
- $user_name = 'root';
- $password = 'admin';
- $conn = mysql_connect($host,$user_name,$password);
- if(!$conn)
- {
- die('數(shù)據(jù)庫連接失敗:'.mysql_error());
- }
- mysql_select_db('test');
- //先判斷是否存在該id的用戶
- $sql = "select * from users where id=$id";
- $result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
- if(!mysql_num_rows($result))
- {
- echo '用戶id錯(cuò)誤!';
- exit;
- }
- //刪除用戶數(shù)據(jù)//開源代碼Vevb.com
- $sql = "delete from users where id=$id";
- mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
- mysql_close($conn);
- echo '數(shù)據(jù)刪除成功,返回<a href="13-12.php">13-12.php</a>查看數(shù)據(jù)';
新聞熱點(diǎn)
疑難解答