32 lines
926 B
PHP
32 lines
926 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../koneksi.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
echo json_encode(['status' => 'error', 'message' => 'Invalid request']);
|
|
exit;
|
|
}
|
|
|
|
$id = intval($_POST['id'] ?? 0);
|
|
$nama = trim($_POST['nama'] ?? '');
|
|
$nomor = trim($_POST['nomor'] ?? '');
|
|
$kategori = trim($_POST['kategori'] ?? '');
|
|
|
|
if ($id <= 0 || empty($nama) || empty($nomor) || empty($kategori)) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Data tidak lengkap']);
|
|
exit;
|
|
}
|
|
|
|
$sql = "UPDATE spbu SET nama = ?, nomor = ?, kategori = ? WHERE id = ?";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("sssi", $nama, $nomor, $kategori, $id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Data SPBU diupdate']);
|
|
} else {
|
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
|
}
|
|
|
|
$stmt->close();
|
|
$conn->close();
|
|
?>
|