24 lines
806 B
PHP
24 lines
806 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['status'=>'error']); exit(); }
|
|
require_once 'db_config.php';
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$id = intval($data['id'] ?? 0);
|
|
|
|
if (!$id) { echo json_encode(['status'=>'error','message'=>'ID tidak valid']); exit(); }
|
|
|
|
// Cegah hapus admin utama (id=1)
|
|
if ($id === 1) { echo json_encode(['status'=>'error','message'=>'Akun admin utama tidak dapat dihapus']); exit(); }
|
|
|
|
$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
|
|
$stmt->bind_param('i', $id);
|
|
|
|
echo $stmt->execute()
|
|
? json_encode(['status'=>'success','message'=>'Akun berhasil dihapus'])
|
|
: json_encode(['status'=>'error','message'=>'Gagal menghapus akun']);
|
|
|
|
$stmt->close();
|
|
$conn->close();
|
|
?>
|