<?php
require_once __DIR__ . '/../../connect.php';

try {
    // Retrieve and validate the 'id' parameter
    $id = filterRequest('id');
    if ($id === null || $id === '') {
        throw new Exception("Missing required parameter: id");
    }

    // Prepare the SQL query to delete the record
    $sql = "DELETE FROM `waitingRides` WHERE `id` = :id";

    // Prepare and execute the statement
    $stmt = $con->prepare($sql);
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();

    // Check the result and print the appropriate message
    if ($stmt->rowCount() > 0) {
        jsonSuccess(null, "Record with ID $id deleted successfully.");
    } else {
        jsonError("No record found with ID $id.");
    }
} catch (PDOException $e) {
    jsonError("Database error: " . $e->getMessage());
} catch (Exception $e) {
    jsonError("Error: " . $e->getMessage());
}
?>