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

if (!isset($_SESSION['teacher_id'])) {
    header("Location: teacher_login.php");
    exit();
}

$teacher_id = $_SESSION['teacher_id'];
$name = $_POST['name'] ?? '';

if (empty($name)) {
    die("Name is required");
}

$sql = "UPDATE teachers SET name = ? WHERE teacher_id = ?";
$stmt = $conn->prepare($sql);

if (!$stmt) {
    die("SQL Error: " . $conn->error);
}

$stmt->bind_param("si", $name, $teacher_id);

if ($stmt->execute()) {
    header("Location: profile.php?success=1");
} else {
    echo "Update failed: " . $stmt->error;
}

$stmt->close();
$conn->close();
?>