How can PHP be used to link a delete button to a specific data entry in a database?

To link a delete button to a specific data entry in a database using PHP, you can pass the unique identifier of the entry (such as an ID) through the URL when the delete button is clicked. In the PHP script that handles the deletion, you can retrieve this identifier from the URL and use it to delete the corresponding entry from the database.

<?php
// Check if the delete button is clicked
if(isset($_GET['delete_id'])){
    // Connect to the database
    $conn = mysqli_connect("localhost", "username", "password", "database");

    // Retrieve the ID from the URL
    $id = $_GET['delete_id'];

    // Delete the entry with the specified ID from the database
    $query = "DELETE FROM table_name WHERE id = $id";
    mysqli_query($conn, $query);

    // Redirect back to the page after deletion
    header("Location: index.php");
    exit();
}
?>