doulandai0641 2014-09-12 03:28
浏览 39
已采纳

期望参数1是资源,更新记录时给出错误的布尔值[重复]

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>
  • 写回答

1条回答 默认 最新

  • douyoupingji7238 2014-09-12 04:03
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失