<?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, academic_session, admission_term FROM students WHERE studentRegNo = ?");

    $stmt->bind_param("s", $optionName);

    $stmt->execute();

    

    // Bind result variables

    $stmt->bind_result($studentName, $class, $stream, $email, $academic_session, $admission_term);

    

    $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;

        $result['academic_session'] = $academic_session;

        $result['admission_term'] = $admission_term;

    } else {

        $result['error'] = "No value found"; // In case no value is found

    }



    // Return data as JSON

    echo json_encode($result);



    $stmt->close();

}



$con->close();

?>

