user2526699 user2526699 - 6 months ago 17
MySQL Question

Issue with a login&register system. Receiving and error

I've searched this issue high and low. I've also seen it asked in many places but never to the point in which i am having the issue. Nor I have found a solution that has fixed mine. I've spent a very long time trying to fix this and I can not move forward until it has been resolved any help would be GREATLY appreciated.

It's a login & register tutorial by phpacademy.

My error is as follows:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\lr\core\functions\users.php on line 5

The code I have for my users.php file is as follows and is 100% the same as is on the tutorial. Mine fails to work his does not.

function user_exists ($username) {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
return (mysql_result($query, 0) == 1) ? true : false;

The following is line 5 from the above code where the error appears to be resulting from.

return (mysql_result($query, 0) == 1) ? true : false;

Thanks again in advance.


This error indicates that your previous statement mysql_query

     $query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");

has returned false, if you check the documentation it states that on failure mysql_query will return false. Therefore we need to come to a conclusion that your query is failing. To find out more information on why your query is failing. Include mysql_error() at the end of the statement.

   $query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'") or die(mysql_error());