<?php
include("koneksi.php");

if ($_SERVER["REQUEST_METHOD"] == "GET") {
    if (isset($_GET['user_id'])) {
        
        $id = intval($_GET['user_id']);

        $sql = "DELETE FROM users WHERE user_id = $id";
        $hasil = mysqli_query($conn, $sql);

        if ($hasil) {
            echo "<script>
                alert('User dengan ID $id berhasil dihapus!');
                window.location.href = '../Admin/admin.php';
            </script>";
        } else {
            echo "<script>
                alert('Gagal menghapus User!');
                window.history.back();
            </script>";
        }
    } else {
        echo "<script>
            alert('ID user tidak ditemukan!');
            window.history.back();
        </script>";
    }
} else {
    header("Location: ../Admin/admin.php");
    exit();
}
?>
