Persiapan hosting: config DB, perbaikan role, fix redirect
This commit is contained in:
+3
-3
@@ -9,7 +9,7 @@ $action = $_POST['action'] ?? $_GET['action'] ?? 'list';
|
||||
// ── LIST ────────────────────────────────────────────────────────
|
||||
if ($action === 'list') {
|
||||
$rows = mysqli_fetch_all(
|
||||
mysqli_query($conn, "SELECT id, username, nama, created_at FROM users ORDER BY nama"),
|
||||
mysqli_query($conn, "SELECT id, username, nama, role, created_at FROM users ORDER BY nama"),
|
||||
MYSQLI_ASSOC
|
||||
);
|
||||
echo json_encode(['status' => 'success', 'data' => $rows]);
|
||||
@@ -27,7 +27,7 @@ if ($action === 'add') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$role = in_array($_POST['role'] ?? '', ['admin','superadmin']) ? $_POST['role'] : 'admin';
|
||||
$role = in_array($_POST['role'] ?? '', ['admin','operator']) ? $_POST['role'] : 'operator';
|
||||
$hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$st = mysqli_prepare($conn, "INSERT INTO users (username, password, nama, role) VALUES (?,?,?,?)");
|
||||
mysqli_stmt_bind_param($st, 'ssss', $username, $hash, $nama, $role);
|
||||
@@ -46,7 +46,7 @@ if ($action === 'update') {
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$pass = $_POST['password'] ?? '';
|
||||
$role = in_array($_POST['role'] ?? '', ['admin','superadmin']) ? $_POST['role'] : 'admin';
|
||||
$role = in_array($_POST['role'] ?? '', ['admin','operator']) ? $_POST['role'] : 'operator';
|
||||
|
||||
if ($id <= 0 || !$nama) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Data tidak valid']);
|
||||
|
||||
Reference in New Issue
Block a user