<?php
include 'includes/config.php'; 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $id = isset($_POST['id']) ? $_POST['id'] : '';

    if ($id) {
        // Prepare the SQL query to fetch contact details
        $sql = "SELECT * FROM contacts WHERE id = :id";
        $stmt = $conn->prepare($sql);
        $stmt->execute([':id' => $id]);
        $contact = $stmt->fetch(PDO::FETCH_ASSOC);

        if ($contact) {
            echo json_encode($contact);
        } else {
            echo json_encode(['error' => 'No contact found']);
        }
    } else {
        echo json_encode(['error' => 'Invalid ID']);
    }
} else {
    echo json_encode(['error' => 'Invalid request method']);
}
?>
