<?php
session_start();
include('connection/config.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $matric = $_POST['matric_number'];

    // Validate matric number
    $stmt = $pdo->prepare("SELECT * FROM students WHERE matric = :matric_number");
    $stmt->bindParam(':matric_number', $matric);
    $stmt->execute();
    
    if ($stmt->rowCount() > 0) {
session_start();
        $_SESSION['matric_number'] = $matric;
        header('Location: cbt2.php');  // Redirect to the question page
        exit();
    } else {
        $error = "Invalid Matric Number!";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>School Login</title>
    <link rel="stylesheet" href="css/indexstyle.css">
</head>
<body>
 <div class="container">
        <h2>GEEDYSTAR </h2>
        <form method="POST" action="">
            <div class="form-group">
                <label for="matric_number">Computer Based Examinationr</label>
                <input type="text" id="matric_number" name="matric_number" placeholder="Type in your Matric No" required>
            </div>
            <button type="submit">Login</button>

            <?php if (isset($error)): ?>
                <p class="error"><?php echo $error; ?></p>
            <?php endif; ?>
        </form>
    </div>

</body>
</html>
