0

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!

3
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by urtrivedi
0

Yup, add quotes to $recover_password:

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

Edited by cereal

0

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;

Edited by cereal

0
    $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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.