Initial commit: WebGIS Kemiskinan Pontianak
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['admin'])) die('Unauthorized');
|
||||
require 'config.php';
|
||||
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$nik = trim($_POST['nik'] ?? '');
|
||||
$family = (int)($_POST['family_size'] ?? 1);
|
||||
$income = (int)($_POST['income'] ?? 0);
|
||||
$rt_rw = trim($_POST['rt_rw'] ?? '-');
|
||||
$lat = (float)($_POST['lat'] ?? 0);
|
||||
$lng = (float)($_POST['lng'] ?? 0);
|
||||
|
||||
if ($name === '') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Nama wajib diisi']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO poor_residents (name, nik, family_size, income, rt_rw, lat, lng) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->bind_param("ssiisdd", $name, $nik, $family, $income, $rt_rw, $lat, $lng);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['success' => true, 'message' => 'Data berhasil disimpan']);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Gagal menyimpan: ' . $stmt->error]);
|
||||
}
|
||||
Reference in New Issue
Block a user