Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?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();
|
||||
?>
|
||||
Reference in New Issue
Block a user