<?php
// Include the database configuration
include 'config.php'; // Ensure the path to config.php is correct

// Check if numDossard is provided in the URL (GET method)
if (isset($_GET['numDossard'])) {
    $numDossard = $_GET['numDossard'];

    // Check if the coureur exists in the database
    $sql = "SELECT * FROM Coureur WHERE numDossard = ?";
    $stmt = mysqli_prepare($conn, $sql);
    mysqli_stmt_bind_param($stmt, "i", $numDossard);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);

    if (mysqli_num_rows($result) > 0) {
        // The runner exists, now delete the record
        $delete_sql = "DELETE FROM Coureur WHERE numDossard = ?";
        $delete_stmt = mysqli_prepare($conn, $delete_sql);
        mysqli_stmt_bind_param($delete_stmt, "i", $numDossard);

        if (mysqli_stmt_execute($delete_stmt)) {
            echo "Coureur with numDossard $numDossard has been deleted successfully.";
        } else {
            echo "Error deleting coureur: " . mysqli_error($conn);
        }
    } else {
        echo "Coureur with numDossard $numDossard does not exist.";
    }

    // Close the prepared statements
    mysqli_stmt_close($stmt);
    mysqli_stmt_close($delete_stmt);
} else {
    echo "No numDossard provided.";
}

// Close the database connection
mysqli_close($conn);
?>
