Initial commit: Upload project WebGIS dengan tema Merah Putih
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// point/simpan.php
|
||||
include '../koneksi.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$no_wa = trim($_POST['no_wa'] ?? '');
|
||||
$buka_24 = trim($_POST['buka_24_jam']?? '');
|
||||
$latitude = trim($_POST['latitude'] ?? '');
|
||||
$longitude = trim($_POST['longitude'] ?? '');
|
||||
|
||||
if (!$nama || !$no_wa || !$buka_24 || !$latitude || !$longitude) {
|
||||
echo json_encode(['status'=>'error','message'=>'Semua field wajib diisi.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!in_array($buka_24, ['Ya','Tidak'])) {
|
||||
echo json_encode(['status'=>'error','message'=>'Nilai buka_24_jam tidak valid.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO points (nama, no_wa, buka_24_jam, latitude, longitude)
|
||||
VALUES (?, ?, ?, ?, ?)"
|
||||
);
|
||||
$stmt->execute([$nama, $no_wa, $buka_24, $latitude, $longitude]);
|
||||
$id = $pdo->lastInsertId();
|
||||
|
||||
$stmtSelect = $pdo->prepare("SELECT * FROM points WHERE id = ?");
|
||||
$stmtSelect->execute([$id]);
|
||||
$data = $stmtSelect->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode(['status'=>'success','data'=>$data]);
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(['status'=>'error','message'=>'Gagal menyimpan: '.$e->getMessage()]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user