Fix SPBU status writes
This commit is contained in:
+20
-10
@@ -1,14 +1,24 @@
|
||||
<?php
|
||||
include 'koneksi.php';
|
||||
|
||||
$id = $_POST['id'];
|
||||
$nama = $_POST['nama'];
|
||||
$wa = $_POST['wa'];
|
||||
$status = $_POST['status'];
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$wa = trim($_POST['wa'] ?? '');
|
||||
$status = $_POST['status'] ?? 'no';
|
||||
|
||||
$conn->query("UPDATE spbu SET
|
||||
nama_spbu='$nama',
|
||||
no_wa='$wa',
|
||||
status='$status'
|
||||
WHERE id=$id");
|
||||
?>
|
||||
if (!in_array($status, ['yes', 'no'], true)) {
|
||||
http_response_code(400);
|
||||
echo "Status tidak valid";
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $conn->prepare("UPDATE spbu SET nama_spbu=?, no_wa=?, status=? WHERE id=?");
|
||||
$stmt->bind_param('sssi', $nama, $wa, $status, $id);
|
||||
$stmt->execute();
|
||||
echo "success";
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
http_response_code(500);
|
||||
echo "error: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user