...

View Full Version : Help with IF statements



four0four
01-30-2010, 02:42 AM
I'm trying to redirect a user to another page based on a certain condition.

However, for some reason, it doesn't redirect and it keeps returning the else statement.

Here's my code:




if (mysql_num_rows($result) == 1 && $userpass == $userData['password']){

if ($userData['active'] == '1'){

header('Location: members.php');

}

if ($userData['active'] == '0'){

header('Location: payment.php');

}

}
else{
echo ("Login failure! Please try again.");
}


When I remove the two nested IF statements, it works fine. Any ideas?

Thanks!

abduraooft
01-30-2010, 08:14 AM
What output do you get for the following ?
print_r($userData);

Dormilich
01-30-2010, 09:48 AM
usually you have to exit the script after you make a header redirect.

thekooliest
01-31-2010, 02:59 AM
Tell me what you see when you replace your above code with this:


if (mysql_num_rows($result) == 1 && $userpass == $userData['password']){

if ($userData['active'] == '1'){

echo 'If you see this, I know your problem.';

}

if ($userData['active'] == '0'){

echo 'If you see this, I know your problem.';

}

}
else{
echo ("Login failure! Please try again.");
}

I think you can't make header requests after any information is sent to the browser...

-Sam

Dormilich
01-31-2010, 08:59 AM
I think you can't make header requests after any information is sent to the browser...

you can, although that triggers an error (or warning?).

MattF
01-31-2010, 09:03 AM
you can, although that triggers an error (or warning?).

It'll log an error and the header won't be sent. Output buffering can be used to prevent that particular scenario arising, however.

hdewantara
02-03-2010, 08:20 PM
Hi four0four:

header('Location: members.php'); should be written as:
header('Location: http://www.absolute.url/members.php');

Not sure whether this would fix your problem but it is HTTP/ 1.1 requirement (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum