Displaying error message after redirecting the user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lawillas
Forum Newbie
Posts: 9
Joined: Sat Mar 28, 2009 4:17 pm

Displaying error message after redirecting the user

Post by lawillas »

Hello everyone....i've been battling with this problem for a while now....I created a login script....everything works well except when i want to display error messages to users after they login with wrong values

when i try to do something like this :
if(mysql_num_rows($query) = 0) {
header("Location : login.php?muta=0&ml=".$_POST['username']);
echo "Invalid login detail";
exit();
}
the above code does display muta=0&ml=..'the username' on the URL but does'nt display the error message, but when i removed the line header ("Location : login.php?muta=0&ml=".$_POST['username']); it displayed the error message.

I need help on this as soon as possible.
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: Displaying error message after redirecting the user

Post by deejay »

it's because the user is being sent away before they get the "Invalid login detail"

That'll need to go on the 'login.php' page that your sending them to if you want them to see the message.


'
lawillas
Forum Newbie
Posts: 9
Joined: Sat Mar 28, 2009 4:17 pm

Re: Displaying error message after redirecting the user

Post by lawillas »

@deejay i dont quite understand wat u saying.....maybe u try nd show me an example
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Displaying error message after redirecting the user

Post by tech603 »

Code: Select all

if(mysql_num_rows($query) = 0) {
header("Location : login.php?muta=0&ml=".$_POST['username']);
echo "Invalid login detail";
exit();
}
What he is saying that in the above code your sending the user back to the login page before you echo out the error message. The easiest way to accomplish what you want is possibly using a meta refresh tag with your instead of using a header redirect, this will allow the page to echo the page message for the designated set time and then redirect.

<meta http-equiv="refresh" content="5;url=http://example.com/" />

Hope that helps
Post Reply