Files
2026-06-10 21:06:57 +07:00

29 lines
701 B
PHP

<?php
require_once '../../auth.php';
requireRole('admin');
header('Content-Type: application/json');
require_once '../../../config.php';
$conn = getDB();
$data = json_decode(file_get_contents("php://input"), true);
$id = (int) $data['id'];
// Tidak boleh hapus diri sendiri
if ($id === (int) $_SESSION['user']) {
echo json_encode(["status" => "error", "message" => "Tidak bisa menghapus akun sendiri"]);
exit;
}
$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo json_encode(["status" => "success"]);
} else {
echo json_encode(["status" => "error", "message" => $stmt->error]);
}
$stmt->close();
$conn->close();
?>