尝试使用函数时出现一个错误,我不知道如何解决。

function is_valid($email_e, $email_code_e, $username_e) {
    $email = mysql_real_escape_string($email_e);
    $email_code = mysql_real_escape_string($email_code_e);
    $username = sanitize($username_e);
    return (mysql_result
               (mysql_query
                   ("SELECT COUNT(*) FROM `users`
                     WHERE `username` = $username
                     AND `email_code` = $email_code
                     AND `email` = $email"), 0) == 1) ? true : false;
 }



  警告:mysql_result()期望参数1为资源,在第34行的/home/meuts3/public_html/core/functions/users.php中给出布尔值


我正在尝试创建一个忘记密码系统,当有人尝试获取新密码时,他会收到一个带有email_codeusernameemail的链接。当他单击时,他进入更改密码页面,在此页面中,我将使用功能is_valid检查这些信息是否有效,因此,如果is_valid我必须返回user_id才能开始会话user_id

我怎样才能做到这一点?

谢谢,我真的很感谢你们。

最佳答案

尝试这个:

function is_valid($email_e,$email_code_e,$username_e) {

    $email = mysql_real_escape_string($email_e);
    $email_code = mysql_real_escape_string($email_code_e);
    $username = sanitize($username_e);

    $sql = "SELECT user_id FROM `users`
            WHERE `username` = $username
              AND `email_code` = $email_code
              AND `email` = $email";

    $result = mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($result) <= 0)
     return -1;

    return  mysql_result($result,1);

}

09-08 05:13