<?php
include('connection.php');
// Check if the edit form is submitted
if (isset($_POST['update'])) {
    $name = $_POST['name'];
    $id = $_POST['id'];
    $address = $_POST['address'];
    $number = $_POST['number'];

    // Update the contact's information in the database
    $updateSql = "UPDATE add_contact SET name = '$name', address = '$address', number = '$number' WHERE id = $id";
    $updateResult = mysqli_query($conn, $updateSql);

    if ($updateResult) {
        // Redirect back to the page with a success message
        header("Location: contact-add.php?success=Contact updated successfully.");
        exit();
    } else {
        // Redirect back to the page with an error message if the update fails
        header("Location:contact-add.php?error=Failed to update contact.");
        exit();
    }
}
?>