<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: index.php');
    exit;
}
require 'dbconn.php';

if (isset($_GET['id']) && isset($_GET['member_id'])) {
    $id = intval($_GET['id']);             // Family member ID
    $member_id = intval($_GET['member_id']); // Parent member ID

    $stmt = $mysqli->prepare("DELETE FROM family_members WHERE id = ? AND member_id = ?");
    $stmt->bind_param("ii", $id, $member_id);

    if ($stmt->execute()) {
        header("Location: family_members.php?member_id=$member_id&deleted=1");
        exit;
    } else {
        echo "❌ Error deleting family member: " . $stmt->error;
    }
} else {
    echo "❌ Invalid request (Missing ID or Member ID)";
}
