PHP連接mysql數據庫進行增刪改查--刪除
阿新 • • 發佈:2017-10-21
點擊 each .com -s itl img ref cati let
刪除:
1、首頁
在foreach裏面加入 <td><a href=‘dele.php?id={$i[0]}‘>刪除</a></td>
在上面<php>裏加入 $sql = "select * from student.student WHERE is_delete = 0"; (第二種修改方法時使用)
2、新建dele.php 創建數據庫刪除
<?php
$id = $_GET[‘id‘];
$db = new Mysqli("localhost","root","root","student");
//1
//$sql = "delete from student.student WHERE sno = {$id}";
//if($db->query($sql)){
// header("location:crud.php");
//};
//2
$sql2 = "update student set is_delete = ‘1‘ WHERE Sno = {$id}";
if($db->query($sql2)){
header("location:crud.php");
}
刪除的兩種方法
1、直接刪除 2、修改數據庫裏is_delete 點擊刪除 裏面的0修改為1 ,但需在主頁裏面加入 只顯示數據庫裏is_delete為0的數據
測試一下
1、點擊刪除 試一下這一行 1213 diiudiudiu 女 1960-08-20 00:00:00 576685
2、顯示
3、成功 ^-^
PHP連接mysql數據庫進行增刪改查--刪除