<?php
include "../include/config.php";

if (isset($_POST['program']) && !empty($_POST['program'])) {
    $program = mysqli_real_escape_string($conn, $_POST['program']);
    
    $sql = "SELECT id, course FROM course WHERE program = '$program' ORDER BY course ASC";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
        echo '<option value="">-- Select Course --</option>';
        while ($row = $result->fetch_assoc()) {
            echo "<option value='" . $row['id'] . "'>" . $row['course'] . "</option>";
        }
    } else {
        echo '<option value="">No courses found</option>';
    }
} else {
    echo '<option value="">Invalid request</option>';
}
?>
