How to implement the delete function
In the main page of the background, we find the Modify/Delete button pattern under the operation column as shown below. In this chapter, we will first talk about how to implement the function of deleting a piece of data.
The main idea of realizing the deletion function is to obtain the id of the data that needs to be deleted, and delete this through SQL statements Book id to delete all records of this id in the database table.
First create a delete.php file
Get it in list.php The path of id is then deleted. Make the following modifications in list.php, $rows["id"] is output through the while loop in the previous section.
<td> <div class="button-group"> <a class="button border-main" href="#"><span class="icon-edit"></span>修 改</a> <a class="button border-red" href="delete.php?id=<?php echo $rows["id"]?>" onclick="return del(1,1,1)"> <span class="icon-trash-o"></span>删 除 </a> </div> </td>
delete.php file, import the database public file config.php, get the value of the id and delete this data in the database. Write the following code:
<?php header("content-type:text/html;charset=utf-8"); include("config.php"); $id = isset($_GET['id'])?$_GET['id']:""; $sql = "delete from list where id = '$id'"; //echo $sql; $rel = mysqli_query($link,$sql); if($rel){ echo "<script>alert('删除成功');window.location.href='list.php'</script>"; }else{ echo "<script>alert('删除失败');window.location.href='list.php'</script>"; } ?>