Jump to content

This is KILLING me!


dudejma

Recommended Posts

I have this code and it will NOT, for the love of GOD, echo out the incorrect login credentials error. I've tried everything but it just won't work! And I've even echoed out $num and it gives me 0, but it still won't echo it! So, I have no idea why it doesn't do it. Does anyone? The other ones work, it'll login or if the status equals what the if statement says, it'll output that, it just will NOT OUTPUT THE OTHER ONE! Gah, I've sat here for hours and can't get it. Watch it be something right there in front of me. :P

 

$num = mysql_num_rows($result);

while($row = mysql_fetch_array($result)) {
if ($row['status'] == 2) {
$errors .= "You are on LOA. To be taken off LOA, please contact the Director of Human Resources.";
} elseif ($row['status'] == 3) {
$errors .= "You have failed to file a PIREP in the amount of time given. Please contact the Director of Human Resources. None of your previous hours will be redeemable.";
} elseif ($row['status'] == 4) {
$errors .= "You are now retired in the virtual airline. If you wish to come back and fly with us, please contact the Director of Human Resources.";
} elseif ($row['status'] == 0) {
$errors .= "You're account has not yet been activated. You will receive an email shortly concerning your application.";
} elseif ($num == 1) {
$_SESSION['pilotid'] = $pilotid;
$_SESSION['password'] = $password;
$_SESSION['staff'] = $row['position'];
header ("Location: pc.php");
} elseif ($num == 0) {
$errors .= "Incorrect login credentials. Please try again.<br />";
}
}

Link to comment
Share on other sites

If there are no rows in the result set, your while(){} loop will be skipped (the while() condition will be false.) Your test of $num==0 is inside of the while(){} block of code and is never executed.

 

You should test if($num==0) first, before the start of the while(){} loop.

 

Since you are expecting either zero or one row from the query, you don't even need a while(){} loop. If there is more than zero rows (one) (not zero rows), just fetch that one row.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.