Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
include "db_config.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$id = isset($data['id']) ? intval($data['id']) : 0;
|
||||
$nama = $conn->real_escape_string($data['nama'] ?? '');
|
||||
$status = $conn->real_escape_string($data['status'] ?? 'Kabupaten');
|
||||
$panjang = isset($data['panjang']) ? floatval($data['panjang']) : 0;
|
||||
$koordinatInput = $data['koordinat'] ?? [];
|
||||
|
||||
if ($id <= 0 || $nama === '') {
|
||||
echo json_encode(["status" => "error", "message" => "Data tidak valid"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (is_string($koordinatInput)) {
|
||||
$decoded = json_decode($koordinatInput, true);
|
||||
$koordinat = (json_last_error() === JSON_ERROR_NONE) ? json_encode($decoded) : '[]';
|
||||
} else {
|
||||
$koordinat = json_encode($koordinatInput);
|
||||
}
|
||||
|
||||
$koordinat = $conn->real_escape_string($koordinat);
|
||||
|
||||
$sql = "UPDATE jalan SET nama='$nama', status='$status', panjang='$panjang', koordinat='$koordinat' WHERE id=$id";
|
||||
|
||||
if ($conn->query($sql)) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user