PHP和HTML代码
<!doctype html><html ><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title></head> <style type="text/css"> table.imagetable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #999999; border-collapse: collapse; } table.imagetable th { background:#b5cfd2 url(‘cell-blue.jpg‘); border-width: 1px; padding: 8px; border-style: solid; border-color: #999999; } table.imagetable td { background:#dcddc0 url(‘cell-grey.jpg‘); border-width: 1px; padding: 8px; border-style: solid; border-color: #999999; }</style><body><table class="imagetable"> <tr> <th>id</th> <th>姓名</th> <th>密码</th> <th>性别</th> <th>系部</th> <th>班级</th> <th>操作</th> //添加一个操作 </tr> <?php header( ‘Content-Type:text/html;charset=utf-8 ‘); include_once("conn/conn.php"); //引入导入数据库控制页面 $sql="SELECT*from user"; //查询数据库中的user; $r=mysqli_query($link,$sql); $row=mysqli_fetch_array($r); //查询出来的数组类型 while ($row=mysqli_fetch_array($r)){ /*print_r($row); echo "<br>";*/ /* echo $row["name"]."=>".$row["mima"]; //查询姓名和密码 也可以用键来查询 echo "<br>";*/ ?> <tr> <td><?php echo $row["id"]?></td> <td><?php echo $row["name"]?></td> <td><?php echo $row["mima"]?></td> <td><?php echo $row["xingbie"]?></td> <!-- 从数据库中查询出的数据装着表格中--> <td><?php echo $row["xibu"]?></td> <td><?php echo $row["banji"]?></td> <td style="color: red;"><a href="shanchu.php?id=<?php echo $row["id"]?>">删除</a></td> //给每一条数据添加上删除按钮 </tr> <?php } ?> </table></body></html> PHP代码
<?phpheader( ‘Content-Type:text/html;charset=utf-8 ‘); include_once("conn/conn.php"); $id=$_GET["id"]; //用get传值$sql="delete from USER WHERE id=$id";$r=mysqli_query($link,$sql);if ($r){ echo "成功,点击<a href=‘shujukuchaxun.php‘>返回</a>";}else{ echo "<script>alert(‘删除失败‘);history.back();</script>";}
时间: 2024-10-11 00:41:52