dudejma Posted August 14, 2011 Share Posted August 14, 2011 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. $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 />"; } } Quote Link to comment https://forums.phpfreaks.com/topic/244727-this-is-killing-me/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2011 Share Posted August 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/244727-this-is-killing-me/#findComment-1256997 Share on other sites More sharing options...
dudejma Posted August 14, 2011 Author Share Posted August 14, 2011 Ohhhhhh! That makes sense! Thanks so much! Gah, freaking life saver. Quote Link to comment https://forums.phpfreaks.com/topic/244727-this-is-killing-me/#findComment-1257000 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.