Files

37 lines
899 B
PHP

<?php
include 'koneksi.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$tabel = isset($_POST['tabel']) ? trim($_POST['tabel']) : '';
if ($id <= 0) {
http_response_code(400);
echo "ID tidak valid!";
exit;
}
$allowed_tables = ['spbu_locations'];
if (in_array($tabel, $allowed_tables)) {
$stmt = $conn->prepare("DELETE FROM $tabel WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo "Data berhasil dihapus!";
} else {
http_response_code(500);
echo "Gagal menghapus: " . $conn->error;
}
$stmt->close();
} else {
http_response_code(400);
echo "Tabel tidak valid!";
}
$conn->close();
} else {
http_response_code(405);
echo "Metode tidak diizinkan";
}
?>