One possibility for the cause of the error could be on the return line of the login function (which obviously returns false):
return(mysql_result($query, 0) === 1) ? $user_id : false;
mysql_result() function returns string so you should compare it to 1 (an integer) with == operator. If you want to use === operator then you should compare it to '1' (a string).
So either:
return(mysql_result($query, 0) == 1) ? $user_id : false;
or:
return(mysql_result($query, 0) === '1') ? $user_id : false;
I have not tested this so I do not claim I am 100% right.
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
I am not sure if this is important: sha1() function should be in lowercase. Can you try
$password = sha1($password);
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
Another desperate try: have you tried to echo the query in the login function:
function login($username, $password)
{
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = SHA1($password);
$query = mysql_query("SELECT COUNT(user_id) FROM users WHERE userName = '$username' AND password = '$password'");
// DEBUG
die($query);
return(mysql_result($query, 0) === 1) ? $user_id : false;
}
Does the query look OK (is user_id correct, is $password actually a hash)? Does the output query work OK in phpmyadmin if you copy it there?
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
And what does the sanitize function do? Does it work correctly?
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
Question Answered as of 5 Months Ago by
broj1