This question already has an answer here:
i have created one reregistration system from which user can register there-self to use my system.
i have created one Verification process to avoid robot
Verification Process:-
i have created on column in database with 'active' name AS DEFINED '0' so what it does when the value is set to be '0' that means user has not activated his/her account so he can't login into my system. If value set to be '1' then account activated and he/she can use the system now.
To set the AS DEFINED value to 1 i have created on function through which i sending out an Email to user's entered email address while reregistration process with random email_code. once he hit that code in URL then AS DEFINED value will be Changed to 1.
Now i stuck with and error i have spend hours to figure out the solution for this
Error :
Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pratik\minimal\core\functions\users.php on line 123
Code :
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(`registration_id`) FROM `register` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0") or die(mysql_error()), 0) == 1) {
mysql_query("UPDATE `register` SET `active` = 1 WHERE `email` = '$email'");
return true;
} else {
return false;
}
}
Please help !!
</div>
You are directly passing a boolean value into mysql_result.
Any argument that looks like <statement> or <statement>
is a boolean. You have
mysql_query(...) or die(...)
If your query doesn't error, this will return true
. Yet another reason or die()
must die.
Here's a simple example to demonstrate what I mean ~ https://eval.in/192040
Also, something something mysql extension something something officially deprecated something something unmaintained
To solve this, I would simple switch to mysqli or PDO and use exception handling. To enable it in mysqli, simply run this before you create your connection
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
Then you can simply use
$stmt = $mysqli->prepare('SELECT 1 FROM `register` WHERE `email` = ? AND `email_code` = ? AND `active` = 0');
$stmt->bind_param('ss', $email, $email_code); // no need to run these through real_escape_string
$stmt->execute();
return $stmt->fetch();
and any errors will be thrown as exceptions (which you can try
and catch
if you like).