<?php
session_start();
include('db_connection.php');

// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Retrieve form data
    $class_id = $_POST['class_id'];
    $day = $_POST['day'];
    $period = $_POST['period'];
    $subject_id = $_POST['subject_id'];
    $teacher_id = $_POST['teacher_id'];
    $time_slot = $_POST['time_slot'];
    $location = $_POST['location'];

    // Prepare an SQL statement to insert the timetable entry
    $sql = "INSERT INTO timetable (class_id, day, period, subject_id, teacher_id, time_slot, location) 
            VALUES (?, ?, ?, ?, ?, ?, ?)";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("isiiiss", $class_id, $day, $period, $subject_id, $teacher_id, $time_slot, $location);

    // Execute the statement and check if it was successful
    if ($stmt->execute()) {
        echo "Timetable entry added successfully!";
    } else {
        echo "Error: " . $stmt->error;
    }

    // Close the statement and the connection
    $stmt->close();
    $conn->close();
} else {
    echo "Invalid request method.";
}
?>
