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

$teacher_id = $_POST['teacher_id'];
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];

// Update teacher details
$query = "UPDATE teachers SET name = ?, subject = ? WHERE teacher_id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("ssi", $name, $subject, $teacher_id);
$stmt->execute();
$stmt->close();

// Update user email
$user_query = "UPDATE users SET email = ? WHERE user_id = (SELECT user_id FROM teachers WHERE teacher_id = ?)";
$stmt = $conn->prepare($user_query);
$stmt->bind_param("si", $email, $teacher_id);
$stmt->execute();
$stmt->close();

header('Location: manage_teachers.php');
?>
