Hi everyone.

I'm trying to verify whether the variables $username and $password_recovery (both are unique - impossible for them to be the same) both come from the same row in the rable 'users'. This is the query I am using:

return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `recover_password` = $recover_password"), 0) == 1) ? true : false;

(yes I know mysql_* functions are out of date, being depreceated etc). I am trying to get the query to return either true or false, but I am getting this error:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in on line 20 (line of the query).

Any ideas? Thanks!

Recommended Answers

All 4 Replies

Yup, add quotes to $recover_password:

mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `recover_password` = '$recover_password'")

Still giving me the same error :/

Ok then use mysql_error() the query fails, maybe because the variables are not set:

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

A part from that consider to use mysql_num_rows() for this task, something like: mysql_num_rows($q) > 0 ? true : false;

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

    $row = mysql_fetch_array($result));

    if($row[0]==1)
       $flag=true;
    else
       $flag=false;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.