Project UAS Sistem Informasi Geografis (SIG)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?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 tidak diterima"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$nama = $data['nama'] ?? '';
|
||||
$no = $data['no'] ?? '';
|
||||
$status = $data['status'] ?? '';
|
||||
$lat = $data['lat'] ?? '';
|
||||
$lng = $data['lng'] ?? '';
|
||||
|
||||
if ($nama == '' || $no == '' || $lat == '' || $lng == '') {
|
||||
echo json_encode(["message" => "Field tidak lengkap"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO spbu (nama, no_spbu, status, latitude, longitude) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->bind_param("sssdd", $nama, $no, $status, $lat, $lng);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["message" => "Data berhasil disimpan", "id" => $stmt->insert_id]);
|
||||
} else {
|
||||
echo json_encode(["message" => "Gagal simpan", "error" => $stmt->error]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user