<?php
require_once __DIR__ . '/../../classes/Database.php';
$db = Database::getInstance();

// ID check
if (!isset($_GET['id']) || empty($_GET['id'])) {
    die("Invalid user ID");
}

$id = intval($_GET['id']);

// Check user exists
$user = $db->fetch("SELECT * FROM users WHERE id = ?", [$id]);

if (!$user) {
    die("User not found");
}

// DELETE user
$delete = $db->query("DELETE FROM users WHERE id = ?", [$id]);

if ($delete) {
    header("Location: users.php?deleted=1");
    exit;
} else {
    echo "Failed to delete user.";
}
