PHP開發 學生管理系統之刪除學生訊息
建立
我們在index.php 頁面做了刪除連結
<a href='javascript:void(0);' onclick='doDel({$ row['id']})'>刪除</a>
也使用了JS的警告框做了刪除確認
<script>
function doDel(id) {
# if(confirm('確認刪除?')) {
# }
</script>
function doDel(id) {
# if(confirm('確認刪除?')) {
# }
</script>
#刪除資訊
##連結資料庫,刪除從刪除頁面傳過來的相關的ID資訊
程式碼如下
<?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');
?>這樣,就完成了我們的刪除功能,我們將我們前面的所有程式碼簡化融合一下#
新建檔案
<?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');
?>
預覽
Clear
- 課程推薦
- 課件下載
課件暫不提供下載,工作人員正在整理中,後期請多關注該課程~ 













