Files
TUGAS_SIG_JOHANESSATRIACHRI…/Projek Jalan/api/delete_road.php
T

27 lines
722 B
PHP

<?php
require_once 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
try {
$data = json_decode(file_get_contents('php://input'), true);
if (!isset($data['id'])) {
http_response_code(400);
echo json_encode(['error' => 'Missing road id']);
exit;
}
$db = getDB();
$stmt = $db->prepare('DELETE FROM roads WHERE id = ?');
$stmt->execute([$data['id']]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
} else {
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);
}
?>