prepare("SELECT * FROM Users WHERE email = ?"); $stmt->execute([$email]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user && password_verify($password, $user['password'])) { // Password is correct, start session $_SESSION['id'] = $user['id']; $_SESSION['name'] = $user['name']; $_SESSION['role'] = $user['role']; // Redirect based on role if ($user['role'] === 'Admin') { header("Location: /admin/dashboard.php"); exit; } else { header("Location: /student/dashboard.php"); exit; } } else { $errors[] = 'Invalid email or password.'; } } catch (PDOException $e) { $errors[] = "Database error: " . $e->getMessage(); } } } require_once __DIR__ . '/../includes/header.php'; ?>

Login