PHP开发 学生管理系统之删除学生信息

创建

我们在index.php 页面做了删除链接

<a href='javascript:void(0);' onclick='doDel({$row['id']})'>删除</a>

还使用了JS的警告框做了删除确认

<script>
   function doDel(id) {
       if(confirm('确认删除?')) {
           window.location='action.php?action=del&id='+id;
       }
   }
</script>

删除信息

链接数据库,删除从删除页面传过来的相关的ID信息

0.jpg

代码如下

<?php
header("content-type:text/html;charset=utf8");
$id = $_GET['id'];
$conn=mysqli_connect("localhost","root","root","study");
mysqli_set_charset($conn,"utf8");
$sql = "delete from stu where id='$id'";
$rw = mysqli_query($conn,$sql);
if ($rw > 0){
    echo "<script>alter('删除成功');</script>";
}else{
    echo "<script>alter('删除失败');</script>";
}
header('Location: index.php');
?>

这样,就完成了我们的删除功能,我们将我们前面的所有代码简化融合一下


Meneruskan pembelajaran
||
<?php header("content-type:text/html;charset=utf8"); $conn=mysqli_connect("localhost","root","root","study"); mysqli_set_charset($conn,"utf8"); $id = $_GET['id']; $sql = "delete from stu where id='$id'"; $rw = mysqli_query($conn,$sql); if ($rw > 0){ echo "<script>alter('删除成功');</script>"; }else{ echo "<script>alter('删除失败');</script>"; } header('Location: index.php'); ?>
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!