Files
2026-06-11 21:14:16 +07:00

39 lines
1.1 KiB
PHP

<?php
include 'koneksi.php';
$nama = trim($_POST['nama'] ?? '');
$nomor = trim($_POST['no'] ?? '');
$status = trim($_POST['status'] ?? '');
$latitudeRaw = $_POST['lat'] ?? null;
$longitudeRaw = $_POST['lng'] ?? null;
$latitude = is_numeric($latitudeRaw) ? (float) $latitudeRaw : null;
$longitude = is_numeric($longitudeRaw) ? (float) $longitudeRaw : null;
$allowedStatus = ['24jam', 'tidak'];
if ($nama === '' || $nomor === '' || !in_array($status, $allowedStatus, true) || $latitude === null || $longitude === null) {
http_response_code(400);
exit('error');
}
$statement = mysqli_prepare(
$conn,
"INSERT INTO spbu (nama, no_spbu, status, latitude, longitude) VALUES (?, ?, ?, ?, ?)"
);
mysqli_stmt_bind_param($statement, "sssdd", $nama, $nomor, $status, $latitude, $longitude);
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);
?>