Home >Backend Development >PHP Problem >How to delete data in php
How to delete data in php: 1. Create a PHP sample file; 2. Connect to the database; 3. Delete the data with the specified id through the "delete from news where id = $id" statement.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to delete data with php?
php implements basic data addition, deletion and modification operations to delete data
Delete information based on id value delete.php
<?php // header('Content-type:text/html;charset=utf-8'); // $conn = @mysqli_connect('localhost','root','123456','itsource'); include('./conn.php'); $id = $_GET['id']; // echo $title.$autor.$source.$content; $sql = "delete from news where id = $id"; $res = mysqli_query($conn,$sql); if($res) { echo '<script>alert("删除成功"); location.href="list.php";</script>'; }else { echo '删除失败'.mysql_error($conn); } echo '<a href="list.php">返回</a>'; ?>
Recommended learning: "PHP video tutorial 》
The above is the detailed content of How to delete data in php. For more information, please follow other related articles on the PHP Chinese website!