First of all Connect to the database
header("Content-type: text/html; charset=utf-8");//Set encoding$con =@mysql_connect("localhost","root","root ") or die("Database connection failed");
mysql_select_db('news') or die("The specified database cannot be opened"); mysql_query("set names utf8");//Set the database Character set
Then get the id
$res = mysql_query($sql);
if($res){ echo "<script>alert('Delete successfully');location .href='newlist.php';</script>";
}else{
echo "<script>alert('Deletion failed');location.href='newlist.php';< ;/script>";
}
In this way, our deletion function has been implemented
The complete code is as follows
<?php header("Content-type: text/html; charset=utf-8");//设置编码 $con =@mysql_connect("localhost","root","root") or die("数据库连接失败"); mysql_select_db('news') or die("指定的数据库不能打开"); mysql_query("set names utf8");//设置数据库的字符集 $id = $_GET['id']; $sql = "delete from new where id='$id'"; $res = mysql_query($sql); if($res){ echo "<script>alert('删除成功');location.href='newlist.php';</script>"; }else{ echo "<script>alert('删除失败');location.href='newlist.php';</script>"; } ?>Next Section