How can the res() function be modified to delete a database entry instead of inserting one?

To modify the res() function to delete a database entry instead of inserting one, we need to change the SQL query from an INSERT statement to a DELETE statement. We also need to pass the appropriate parameters to identify the specific entry to be deleted.

function res($id) {
    $conn = new mysqli("localhost", "username", "password", "database");

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "DELETE FROM table_name WHERE id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        echo "Record deleted successfully";
    } else {
        echo "Error deleting record: " . $conn->error;
    }

    $stmt->close();
    $conn->close();
}