<?php
include('includes/dbconnection.php');

// Get the selected option from AJAX request
if (isset($_GET['option'])) {
    $optionName = $_GET['option'];

    // Prepare and bind
    $stmt = $con->prepare("SELECT studentName, class, stream, email FROM students WHERE studentno = ?");
    $stmt->bind_param("s", $optionName);
    $stmt->execute();
    
    // Bind result variables
    $stmt->bind_result($studentName, $class, $stream, $email);
    
    $result = array(); // Initialize an array to hold the results

    if ($stmt->fetch()) {
        // Store the values in the array
        $result['studentName'] = $studentName;
        $result['class'] = $class;
        $result['stream'] = $stream;
        $result['email'] = $email;
    } else {
        $result['error'] = "No value found"; // In case no value is found
    }

    // Return data as JSON
    echo json_encode($result);

    $stmt->close();
}

$con->close();
?>
