prepare("SELECT user_id, first_name, last_name, password, role FROM users WHERE email = ? AND role = ?"); $stmt->bind_param("ss", $email, $role); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { $error = "Invalid email or role combination."; } else { $user = $result->fetch_assoc(); if (password_verify($password, $user['password'])) { // Login successful $_SESSION['user_id'] = $user['user_id']; $_SESSION['first_name'] = $user['first_name']; $_SESSION['role'] = $user['role']; // Redirect based on role if ($user['role'] === 'learner') { header("Location: dashboard/student/index.php"); } elseif ($user['role'] === 'instructor' || $user['role'] === 'admin') { header("Location: dashboard/admin/index.php"); } else { $error = "Unknown role."; } if (empty($error)) { ob_end_flush(); exit(); } } else { $error = "Incorrect password."; } } $stmt->close(); } } ?> Login - Psalms Academy
Loading...