How can PHP be used to delete specific entries in a database table based on user input?

To delete specific entries in a database table based on user input, you can use PHP to capture the input data, sanitize it to prevent SQL injection, and then execute a DELETE query with the specified criteria.

<?php
// Assuming connection to database is already established

if(isset($_POST['delete_entry'])) {
    $entry_id = $_POST['entry_id']; // Assuming entry_id is the identifier for the entry to be deleted

    // Sanitize the input
    $entry_id = mysqli_real_escape_string($connection, $entry_id);

    // Execute the DELETE query
    $query = "DELETE FROM table_name WHERE entry_id = '$entry_id'";
    $result = mysqli_query($connection, $query);

    if($result) {
        echo "Entry deleted successfully.";
    } else {
        echo "Error deleting entry: " . mysqli_error($connection);
    }
}
?>