28 lines
761 B
PHP
28 lines
761 B
PHP
<?php
|
|
include 'koneksi.php';
|
|
header('Content-Type: application/json');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
echo json_encode(['status' => 'error', 'message' => 'Invalid method']);
|
|
exit;
|
|
}
|
|
|
|
$id_occupant = $_POST['id_occupant'] ?? '';
|
|
$access = $_POST['access'] ?? '';
|
|
|
|
if (empty($id_occupant) || empty($access)) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Data tidak lengkap']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("UPDATE occupant SET access = ? WHERE id_occupant = ?");
|
|
$stmt->execute([$access, $id_occupant]);
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Access updated']);
|
|
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['status' => 'error', 'message' => 'DB error: ' . $e->getMessage()]);
|
|
}
|
|
?>
|