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

43 lines
1.3 KiB
PHP

<?php
include 'koneksi.php';
$namaKepalaKeluarga = trim($_POST['nama_kepala_keluarga'] ?? '');
$jumlahKkRaw = $_POST['jumlah_kk'] ?? null;
$jumlahKk = filter_var($jumlahKkRaw, FILTER_VALIDATE_INT);
$alamat = trim($_POST['alamat'] ?? '');
$latitudeRaw = $_POST['lat'] ?? null;
$longitudeRaw = $_POST['lng'] ?? null;
$latitude = is_numeric($latitudeRaw) ? (float) $latitudeRaw : null;
$longitude = is_numeric($longitudeRaw) ? (float) $longitudeRaw : null;
if ($namaKepalaKeluarga === '' || $alamat === '' || $jumlahKk === false || $jumlahKk === null || $jumlahKk < 1 || $latitude === null || $longitude === null) {
http_response_code(400);
exit('error');
}
$statement = null;
try {
$statement = mysqli_prepare(
$conn,
"INSERT INTO kemiskinan (nama_kepala_keluarga, jumlah_kk, alamat, latitude, longitude) VALUES (?, ?, ?, ?, ?)"
);
mysqli_stmt_bind_param($statement, "sisdd", $namaKepalaKeluarga, $jumlahKk, $alamat, $latitude, $longitude);
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);
}
?>