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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $teacher_id = $_POST['teacher_id'];
    $day = $_POST['day'];
    $start_time = $_POST['start_time'];
    $end_time = $_POST['end_time'];
    $subject = $_POST['subject'];

    // Insert schedule into database
    $insert_query = "INSERT INTO teacher_schedules (teacher_id, day, start_time, end_time, subject) VALUES (?, ?, ?, ?, ?)";
    $stmt = $conn->prepare($insert_query);
    $stmt->bind_param("issss", $teacher_id, $day, $start_time, $end_time, $subject);
    $stmt->execute();
    $stmt->close();

    // Redirect to view_teacher.php or any appropriate page
    header('Location: view_schedule.php?id=' . $teacher_id);
    exit();
} else {
    // Handle invalid request
    header('Location: add_schedule.php');
    exit();
}
?>
