44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
include 'koneksi.php';
|
|
|
|
$namaMasjid = trim($_POST['nama_masjid'] ?? '');
|
|
$picMasjid = trim($_POST['pic_masjid'] ?? '');
|
|
$alamat = trim($_POST['alamat'] ?? '');
|
|
$latitudeRaw = $_POST['lat'] ?? null;
|
|
$longitudeRaw = $_POST['lng'] ?? null;
|
|
$radiusRaw = $_POST['radius'] ?? 500;
|
|
$latitude = is_numeric($latitudeRaw) ? (float) $latitudeRaw : null;
|
|
$longitude = is_numeric($longitudeRaw) ? (float) $longitudeRaw : null;
|
|
$radius = is_numeric($radiusRaw) ? (float) $radiusRaw : null;
|
|
|
|
if ($namaMasjid === '' || $picMasjid === '' || $alamat === '' || $latitude === null || $longitude === null || $radius === null || $radius < 100 || $radius > 5000) {
|
|
http_response_code(400);
|
|
exit('error');
|
|
}
|
|
|
|
$statement = null;
|
|
|
|
try {
|
|
$statement = mysqli_prepare(
|
|
$conn,
|
|
"INSERT INTO masjid (nama_masjid, pic_masjid, alamat, latitude, longitude, radius) VALUES (?, ?, ?, ?, ?, ?)"
|
|
);
|
|
|
|
mysqli_stmt_bind_param($statement, "sssddd", $namaMasjid, $picMasjid, $alamat, $latitude, $longitude, $radius);
|
|
|
|
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();
|
|
}
|
|
|
|
if ($statement) {
|
|
mysqli_stmt_close($statement);
|
|
}
|
|
?>
|