<?php
include('connection.php');

if (isset($_GET['id'])) {
    $contactId = $_GET['id'];
    
    // Perform the DELETE operation in your database
    $sql = "DELETE FROM add_contact WHERE id = $contactId";
    $result = mysqli_query($conn, $sql);

    if ($result) {
        // Redirect back to the page where contacts are displayed with a success message
        header("Location: contact-add.php?success=Contact deleted successfully.");
        exit();
    } else {
        // Redirect back to the page with an error message if the deletion fails
        header("Location: contact-add.php?error=Failed to delete contact.");
        exit();
    }
} else {
    // Handle the case where 'id' is not set in the URL
    header("Location: contact-add.php?error=Contact ID not provided.");
    exit();
}
?>
