Hi, i am getting this error for an email activation function. can someone help me removing this error message and make it work?

Error:

Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/prevpxmj/public_html/core/functions/users.php on line 6

Code:
<?php
function activate($email, $email_code){
    $email = mysql_real_escape_string($email);
    $email_code = mysql_real_escape_string($email_code);

    if (mysql_result(mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0)==1) {
        // query to upadate user activa status
        mysql_query("UPDATE `users` SET `activate` = 1 WHERE `email` = '$email'");
        return true;
    } else {
        return false;    
    }
}
?>

It means that your select query isn't returning any results, probably due to some kind of error. Maybe you could try to output a mysql_error()? Just put the following statement before the return functions: echo mysql_error(); and see what it does.

  • Try the following it may work -
    in line 6:
    1) remove the word COUNT
    2) change

    (userid) to userid

without brackets

3) change

0" to `0`"
if (mysql_result(mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0)==1) {

Error in this line....
mysql_result reference read this.....Click Here
Return type is String and u are compairing it with 1.....

Instead of this use....."mysql_num_rows"
For Reference read this

if (mysql_result(mysql_query("SELECT COUNT (`userid`) FROM `users` WHERE `email` = '$email', `email_code` = '$email_code' AND `active` = 0"), 0)==1) {

Try comma in place of the First 'AND'

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.