prepare($sql); $stmt->execute(['identifier' => $login_identifier]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user && password_verify($password, $user['password_hash'])) { // Password is correct, set session variables $_SESSION['user_id'] = $user['id']; $_SESSION['full_name'] = $user['full_name']; $_SESSION['user_role'] = $user['user_role']; // Redirect based on user role if ($user['user_role'] === 'admin') { header("Location: admin/dashboard.php"); } else { // For other users, redirect to the main page or a user-specific dashboard header("Location: index.php"); } exit(); } else { // Invalid credentials $error = "Invalid login credentials. Please try again."; } } else { $error = "Database connection failed. Please try again later."; } } // If there was an error, store it in the session to display it if ($error) { $_SESSION['message'] = $error; $_SESSION['alert_type'] = 'danger'; header("Location: login.php"); exit(); } } ?> Login - MyMech

Login to Your Account

"; echo htmlspecialchars($message); echo ''; echo "
"; // Unset the session variables so they don't persist unset($_SESSION['message']); unset($_SESSION['alert_type']); } ?>

Don't have an account? Register here.