<?php
// assign_symbol_numbers.php
include('session_validator.php');
// Include your database connection code here
include('includes/db.php'); // Adjust the path based on your file structure

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve data from the AJAX request
    $examType = $_POST['examType'];
    $selectedClasses = $_POST['selectedClasses'];
    $symbolNumbers = $_POST['symbolNumbers'];

    // Process the data and update the database
    // Example: Loop through $symbolNumbers and update the database
    foreach ($symbolNumbers as $studentId => $symbolNumber) {
        // Perform the database update (replace with your actual SQL query)
        $query = "UPDATE students SET symbol_no = $symbolNumber WHERE student_id = $studentId";
        
        // Execute the query
        $result = $conn->query($query);

        // Check for errors
        if (!$result) {
            // Handle the error (you might want to log it)
            echo "Error updating database: " . $conn->error;
            http_response_code(500); // Internal Server Error
            exit();
        }
    }

    // Send a response back to the client (if needed)
    echo "Symbol numbers assigned successfully";
} else {
    // Handle invalid requests or direct access to the script
    http_response_code(400);
    echo "Invalid request";
}

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