refactor: migrate API scripts to a centralized directory and implement shared database configuration

This commit is contained in:
superbia-17
2026-06-12 23:54:55 +07:00
parent 4424a57a0d
commit 5f1da32298
4 changed files with 9 additions and 4 deletions
+14
View File
@@ -0,0 +1,14 @@
<?php
require_once __DIR__ . '/config.php';
$conn = getDB();
$id = $_POST['id'];
if ($id) {
$stmt = $conn->prepare("DELETE FROM worship_places WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo "Deleted";
}
}
?>
+15
View File
@@ -0,0 +1,15 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/config.php';
$conn = getDB();
$result = $conn->query("SELECT * FROM worship_places");
$places = [];
while($row = $result->fetch_assoc()) {
$places[] = $row;
}
echo json_encode($places);
$conn->close();
?>
+19
View File
@@ -0,0 +1,19 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/config.php';
$conn = getDB();
$name = $_POST['name'];
$lat = $_POST['lat'];
$lng = $_POST['lng'];
$radius = $_POST['radius'];
$type = $_POST['type'];
$address = $_POST['address']; // Capture the address
$stmt = $conn->prepare("INSERT INTO worship_places (name, lat, lng, radius, type, address) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssdiss", $name, $lat, $lng, $radius, $type, $address);
if ($stmt->execute()) {
echo json_encode(["id" => $conn->insert_id]);
}
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
require_once __DIR__ . '/config.php';
$conn = getDB();
$id = $_POST['id'];
$rad = $_POST['radius'];
$stmt = $conn->prepare("UPDATE worship_places SET radius = ? WHERE id = ?");
$stmt->bind_param("ii", $rad, $id);
$stmt->execute();
?>