38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
include __DIR__ . '/../../db_config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
$nama = $_POST['nama'] ?? '';
|
|
$nomor = $_POST['nomor'] ?? '';
|
|
$status = $_POST['status'] ?? 'tidak';
|
|
|
|
if ($id <= 0 || empty($nama) || empty($nomor)) {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'error', 'message' => 'Data tidak lengkap']);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $conn->prepare("UPDATE locations SET nama = ?, nomor = ?, buka_24jam = ? WHERE id = ?");
|
|
if (!$stmt) {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => $conn->error]);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
$stmt->bind_param("sssi", $nama, $nomor, $status, $id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Detail SPBU berhasil diperbarui']);
|
|
} else {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
|
}
|
|
|
|
$stmt->close();
|
|
}
|
|
$conn->close();
|
|
?>
|