Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:31:32+00:00 2026-05-27T21:31:32+00:00

I suspected this wouldn’t work, and it didn’t – but I can’t seem to

  • 0

I suspected this wouldn’t work, and it didn’t – but I can’t seem to find a similar question anywhere so here we go. I had a if else statement that checked to see if they couldn’t log in it would show why (errors), and if there were, they would be echoed out, and otherwise, $_SESSION would be assigned a user id (having already been started beforehand) that was retrieved from a variable that equates to a function which queries the mySQL db. and the page would redirect to an account page, as so:

if (!empty($errors)) {
    foreach ($errors as $error) {
        echo $error . '<br />'; .
    }
} else {
    $_SESSION['user_id'] = $login;
    header('Location: you/default.php');
    exit();
}

The problem is this login form is in a dropdown menu on the homepage (rather than being a page in it’s own right), and if they can’t log in (incorrect password, an unfilled field, etc), I want to redirect to the login.php page and then display the errors, so I tried adding header('Location: login.php'); before the foreach statement, but it just redirected to login.php, like I expected, and didn’t bring the errors along with it.

I suspect this may be a job for AJAX or something other than PHP… ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:31:32+00:00Added an answer on May 27, 2026 at 9:31 pm

    I actually figured out a way to do this myself. In my case if there were errors (if (!empty($errors))), I applied them to the $_SESSION superglobal as $_SESSION['errors'].

    It then redirects the page to login.php where a simple if statement echos them out there:

        if (isset($_SESSION['lqerrors'])) {
        $lqerrors = $_SESSION['lqerrors'];
            foreach ($lqerrors as $lqerror) {
                echo $lqerror, '<br />'; 
            }
        unset($lqerrors,$lqerror,$_SESSION['lqerrors']);
    } 
    

    Easy!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question here but I'm sure there are many more to
I am sure this has been asked before, but I have yet to find
I suspect this applies to general ASP.Net too but I am not sure. If
I suspect this is impossible, but thought I'd ask. Say I have a class
I've read several posts on SO on similar subjects, but was unable to dissect
This is really strange but this code is working fine unless the value entered
I can't seem to handle a CSV I got. It's a file generated by
I am new to both DBs and Rails (using 3.2), and I suspect this
One day I suspect I'll have to learn hadoop and transfer all this data
I'm trying to add multiple jQuery data entries to a single element. I suspected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.