<?php
// Connect to your database 
require('shikanisha.kts.php');

if (isset($_POST['age_group'])) {
    $ageGroup = $_POST['age_group'];

    // Query the database to fetch cost based on the selected age group
    $sql = "SELECT cost FROM swimming WHERE age_group = '$ageGroup'";
    $result = $conn->query($sql);

    if ($result) {
        if ($result->num_rows > 0) {
            $row = $result->fetch_assoc();
            $response = array("success" => true, "cost" => $row['cost']);
        } else {
            $response = array("success" => false);
        }
    } else {
        $response = array("success" => false);
    }

    // Close the database connection
    $conn->close();

    // Send JSON response back to the JavaScript
    header('Content-Type: application/json');
    echo json_encode($response);
} else {
    // Invalid request
    header('HTTP/1.1 400 Bad Request');
}
?>
