News list display, delete function PHP code

<?php
session_start();
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","root","root","news");
mysqli_set_charset($link,"utf8");
if (!$link) {
    die("连接失败: " . mysqli_connect_error());
}
//连接数据库
$SQL = "SELECT * FROM  NEW";//设置查询指令
$result=mysqli_query($link,$SQL);//执行查询
$idD = isset($_GET['idD'])?$_GET['idD']:'';
if($idD){
    $sqlD = "delete from new where id = {$idD}";
    $result = mysqli_query($link, $sqlD);
    if($result){
        echo "<script>alert('删除成功');window.location.href='lists.php'</script>";
    }else{
        echo "<script>alert('操作错误');window.location.href='lists.php'</script>";
    }
}
?>

The above code is all the code to delete the display. Simply put, it is the operation of the database.

Many people will wonder why there are no codes displayed in the list, but only deleted ones. In the previous section, we talked about a loop statement. In fact, that loop has already displayed the database data on the list page.

First connect to the database, execute a query on the database, and pass the obtained value to the front-end page. Next is deletion, executing the statement to delete the database.

Continuing Learning
||
<?php session_start(); header("content-type:text/html;charset=utf-8"); //连接数据库 $link = mysqli_connect("localhost","root","root","news"); mysqli_set_charset($link,"utf8"); if (!$link) { die("连接失败: " . mysqli_connect_error()); } //连接数据库 $SQL = "SELECT * FROM NEW";//设置查询指令 $result=mysqli_query($link,$SQL);//执行查询 $idD = isset($_GET['idD'])?$_GET['idD']:''; if($idD){ $sqlD = "delete from new where id = {$idD}"; $result = mysqli_query($link, $sqlD); if($result){ echo "<script>alert('删除成功');window.location.href='lists.php'</script>"; }else{ echo "<script>alert('操作错误');window.location.href='lists.php'</script>"; } } ?>
submitReset Code