<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = md5($_POST['password']);
    $phone_number = $_POST['phone_number'];
    $gender = $_POST['gender'];

    // $conn = new mysqli('localhost', 'root', '', 'teacher_portal');
        include '../config.php';

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $stmt = $conn->prepare("INSERT INTO teachers (name, email, password, phone_number, gender) VALUES (?, ?, ?, ?, ?)");
    $stmt->bind_param("sssss", $name, $email, $password, $phone_number, $gender);

    if ($stmt->execute()) {
        header("Location: ../index.php");
       $_SESSION['mess'] = 'Registration was successful';
    } else {
         header("Location: ../register.php");
        $_SESSION['errmsg'] = "Error: " . $stmt->error;
    }

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