first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
include 'koneksi.php';
|
||||
|
||||
$idRaw = $_POST['id'] ?? null;
|
||||
$id = filter_var($idRaw, FILTER_VALIDATE_INT);
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$status = trim($_POST['status'] ?? '');
|
||||
$allowedStatus = ['SHM', 'HGB', 'HGU', 'HP'];
|
||||
|
||||
if ($id === false || $id === null || $id <= 0 || $nama === '' || !in_array($status, $allowedStatus, true)) {
|
||||
http_response_code(400);
|
||||
exit('error');
|
||||
}
|
||||
|
||||
$statement = mysqli_prepare(
|
||||
$conn,
|
||||
"UPDATE kavling SET nama = ?, status = ? WHERE id = ?"
|
||||
);
|
||||
|
||||
mysqli_stmt_bind_param($statement, "ssi", $nama, $status, $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);
|
||||
?>
|
||||
Reference in New Issue
Block a user