Files
d1041231044_webgis_spbu/php/update.php
T
2026-06-11 21:14:16 +07:00

37 lines
925 B
PHP

<?php
include 'koneksi.php';
$idRaw = $_POST['id'] ?? null;
$id = filter_var($idRaw, FILTER_VALIDATE_INT);
$nama = trim($_POST['nama'] ?? '');
$nomor = trim($_POST['no'] ?? '');
$status = trim($_POST['status'] ?? '');
$allowedStatus = ['24jam', 'tidak'];
if ($id === false || $id === null || $id <= 0 || $nama === '' || $nomor === '' || !in_array($status, $allowedStatus, true)) {
http_response_code(400);
exit('error');
}
$statement = mysqli_prepare(
$conn,
"UPDATE spbu SET nama = ?, no_spbu = ?, status = ? WHERE id = ?"
);
mysqli_stmt_bind_param($statement, "sssi", $nama, $nomor, $status, $id);
try {
if (mysqli_stmt_execute($statement)) {
echo 'success';
} else {
http_response_code(500);
echo 'error';
}
} catch (mysqli_sql_exception $exception) {
http_response_code(500);
echo 'error: ' . $exception->getMessage();
}
mysqli_stmt_close($statement);
?>