<?php
include("includes/db.php");

// Ensure the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Sanitize inputs
    $id = intval($_POST['id']);
    $examDate = $_POST['editExamDate'];

    // Update query
    $updateQuery = "UPDATE `examination_routine` SET `exam_date` = ? WHERE `id` = ?";

    // Prepare and execute the statement
    if ($stmt = $conn->prepare($updateQuery)) {
        $stmt->bind_param("si", $examDate, $id);
        
        // Execute the statement
        if ($stmt->execute()) {
            // Success: Redirect or display a success message
            header("Location: manage_rouitne.php");
            exit();
        } else {
            // Error: Redirect or display an error message
            header("Location: error.php");
            exit();
        }

        // Close the statement
        $stmt->close();
    }

    // Close the connection
    $conn->close();
} else {
    // Redirect if the form is not submitted
    header("Location: index.php");
    exit();
}
?>
