jmfillman Posted June 12, 2010 Share Posted June 12, 2010 The function below always returns true, no matter what I pass for $eMail and $Password and I can't figure out why!! Please help! public function validateUser($eMail, $Password) { $email = $eMail; $pass = $Password; $query = "SELECT * FROM regUsers WHERE eMail='$email' AND Password='$pass'"; $validResult = mysql_query($query); if(!$validResult) { $msg=$this->err_prefix."Your e-mail and/or Password do not match. ".$this->mysql->error; throw new Exception($msg); } else { return true; } } Quote Link to comment https://forums.phpfreaks.com/topic/204541-select-statement-help/ Share on other sites More sharing options...
Psycho Posted June 12, 2010 Share Posted June 12, 2010 You are not checking the "results" of the query. You are merely checking to see if the query ran successfully, i.e. without errors: public function validateUser($eMail, $Password) { $query = "SELECT * FROM regUsers WHERE eMail='$eMail' AND Password='$Password'"; $result = mysql_query($query); if(!$validResult) { //Query did not run $msg = $this->err_prefix."There was an error running the query. ".$this->mysql->error; throw new Exception($msg); return false; } else if (mysql_num_rows($result)!=1) { //Query ran, but there were no results $msg = $this->err_prefix."Your e-mail and/or Password do not match."; throw new Exception($msg); return false; } return true; } Quote Link to comment https://forums.phpfreaks.com/topic/204541-select-statement-help/#findComment-1071028 Share on other sites More sharing options...
jmfillman Posted June 12, 2010 Author Share Posted June 12, 2010 Thank you! Shouldn't there be another else at the end? else { return true; } Quote Link to comment https://forums.phpfreaks.com/topic/204541-select-statement-help/#findComment-1071039 Share on other sites More sharing options...
Psycho Posted June 12, 2010 Share Posted June 12, 2010 No need. The first two conditions will return false. So, if either of the failures occur it will never get to the return true. Only if the first two error confitions don't apply will the return true get processed. Quote Link to comment https://forums.phpfreaks.com/topic/204541-select-statement-help/#findComment-1071042 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.