36 lines
920 B
PHP
36 lines
920 B
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_write_access_json();
|
|
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'] ?? '';
|
|
$kode = $data['no'] ?? '';
|
|
$lat = $data['lat'] ?? '';
|
|
$lng = $data['lng'] ?? '';
|
|
|
|
if ($nama === '' || $kode === '' || $lat === '' || $lng === '') {
|
|
echo json_encode(["message" => "Field tidak lengkap"]);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $conn->prepare("INSERT INTO points (nama, kode_point, latitude, longitude) VALUES (?, ?, ?, ?)");
|
|
$stmt->bind_param("ssdd", $nama, $kode, $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]);
|
|
}
|
|
|
|
$stmt->close();
|
|
$conn->close();
|
|
?>
|