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

37 lines
1.0 KiB
PHP

<?php
include 'koneksi.php';
$idRaw = $_POST['id'] ?? null;
$id = filter_var($idRaw, FILTER_VALIDATE_INT);
$namaKepalaKeluarga = trim($_POST['nama_kepala_keluarga'] ?? '');
$jumlahKkRaw = $_POST['jumlah_kk'] ?? null;
$jumlahKk = filter_var($jumlahKkRaw, FILTER_VALIDATE_INT);
$alamat = trim($_POST['alamat'] ?? '');
if ($id === false || $id === null || $id <= 0 || $namaKepalaKeluarga === '' || $jumlahKk === false || $jumlahKk === null || $jumlahKk < 1 || $alamat === '') {
http_response_code(400);
exit('error');
}
$statement = mysqli_prepare(
$conn,
"UPDATE kemiskinan SET nama_kepala_keluarga = ?, jumlah_kk = ?, alamat = ? WHERE id = ?"
);
mysqli_stmt_bind_param($statement, "sisi", $namaKepalaKeluarga, $jumlahKk, $alamat, $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);
?>