first commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include 'koneksi.php';
|
||||
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$status = trim($_POST['status'] ?? '');
|
||||
$luasRaw = $_POST['luas'] ?? null;
|
||||
$luas = is_numeric($luasRaw) ? (float) $luasRaw : null;
|
||||
$geom = trim($_POST['geom'] ?? '');
|
||||
$allowedStatus = ['SHM', 'HGB', 'HGU', 'HP'];
|
||||
|
||||
if ($nama === '' || $geom === '' || !in_array($status, $allowedStatus, true) || $luas === null) {
|
||||
http_response_code(400);
|
||||
exit('error');
|
||||
}
|
||||
|
||||
$statement = mysqli_prepare(
|
||||
$conn,
|
||||
"INSERT INTO kavling (nama, status, luas, geom) VALUES (?, ?, ?, ?)"
|
||||
);
|
||||
|
||||
mysqli_stmt_bind_param($statement, "ssds", $nama, $status, $luas, $geom);
|
||||
|
||||
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);
|
||||
?>
|
||||
Reference in New Issue
Block a user