Files
WebGIS-PovertyMapping/php/delete.php
T

37 lines
936 B
PHP

<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
$id = intval($_GET['id'] ?? 0);
$type = $_GET['type'] ?? '';
if ($id == 0 || $type == '') {
echo json_encode(["message" => "Parameter tidak valid"]);
exit;
}
$table = '';
if ($type == 'point') $table = 'points';
if ($type == 'spbu') $table = 'spbu';
if ($type == 'line') $table = 'jalan';
if ($type == 'polygon') $table = 'parsil';
if ($type == 'masjid') $table = 'masjid';
if ($type == 'penduduk') $table = 'penduduk_miskin';
if ($table == '') {
echo json_encode(["message" => "Type tidak dikenali"]);
exit;
}
$stmt = $conn->prepare("DELETE FROM $table WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo json_encode(["message" => "Data berhasil dihapus"]);
} else {
echo json_encode(["message" => "Gagal hapus", "error" => $stmt->error]);
}
?>