Initial commit untuk UAS SIG
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// ============================================
|
||||
// update_jalan.php — Update Jalan Data
|
||||
// ============================================
|
||||
|
||||
require_once 'koneksi.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Method not allowed']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = getConnection();
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($data['id'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID is required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = intval($data['id']);
|
||||
$nama_jalan = $data['nama_jalan'] ?? null;
|
||||
$status = $data['status'] ?? null;
|
||||
$panjang = $data['panjang'] ?? null;
|
||||
$geom = $data['geom'] ?? null;
|
||||
|
||||
$errors = [];
|
||||
|
||||
if (empty($nama_jalan)) $errors[] = 'Nama Jalan is required';
|
||||
if (empty($status)) $errors[] = 'Status is required';
|
||||
if ($panjang === null) $errors[] = 'Panjang is required';
|
||||
if (empty($geom)) $errors[] = 'Geometry is required';
|
||||
|
||||
if (!empty($errors)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => implode(', ', $errors)]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare('UPDATE jalan SET nama_jalan = ?, status = ?, panjang = ?, geom = ? WHERE id = ?');
|
||||
$stmt->bind_param('ssdsi', $nama_jalan, $status, $panjang, $geom, $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['success' => true, 'message' => 'Jalan updated successfully', 'data' => ['id' => $id]]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to update Jalan: ' . $conn->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user