'error', 'message' => 'Method tidak diizinkan.']); exit; } require_once 'koneksi.php'; $tipe = isset($_POST['tipe']) ? trim($_POST['tipe']) : ''; $id = isset($_POST['id']) ? intval($_POST['id']) : 0; if ($id <= 0) { echo json_encode(['status' => 'error', 'message' => 'ID tidak valid.']); exit; } // Mapping tipe ke nama tabel $tabel_map = [ 'spbu' => 'spbu', 'polyline' => 'polyline', 'polygon' => 'polygon', ]; if (!array_key_exists($tipe, $tabel_map)) { echo json_encode(['status' => 'error', 'message' => 'Tipe tidak dikenali.']); exit; } $tabel = $tabel_map[$tipe]; // Prepared statement hapus berdasarkan tipe dan id $stmt = $koneksi->prepare("DELETE FROM `{$tabel}` WHERE id = ?"); $stmt->bind_param('i', $id); if ($stmt->execute()) { if ($stmt->affected_rows > 0) { echo json_encode([ 'status' => 'success', 'message' => ucfirst($tipe) . ' berhasil dihapus.', 'id' => $id, 'tipe' => $tipe ]); } else { echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan.']); } } else { echo json_encode(['status' => 'error', 'message' => 'Gagal menghapus: ' . $stmt->error]); } $stmt->close(); $koneksi->close();