Project UAS Sistem Informasi Geografis (SIG)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
include 'db.php';
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
if (!$data) {
|
||||
echo json_encode(["message" => "Data kosong"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$nama = $data['nama'] ?? '';
|
||||
$status = $data['status'] ?? '';
|
||||
$panjang = $data['panjang'] ?? 0;
|
||||
$geom = $data['geom'] ?? ''; // ✅ sudah string JSON dari JS, JANGAN json_encode lagi
|
||||
|
||||
if ($nama === '' || $geom === '') {
|
||||
echo json_encode(["message" => "Field tidak lengkap"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO jalan (nama, status, panjang, geom) VALUES (?, ?, ?, ?)");
|
||||
|
||||
if (!$stmt) {
|
||||
echo json_encode(["message" => "Prepare gagal", "error" => $conn->error]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->bind_param("ssds", $nama, $status, $panjang, $geom);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["message" => "Berhasil", "id" => $stmt->insert_id]);
|
||||
} else {
|
||||
echo json_encode(["message" => "Gagal", "error" => $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user