1

我在一个名为 user.php 的文件中有以下函数:

        function user_id_from_username($username) {
            $username = sanitize($username);
            return mysql_result(mysql_query("SELECT `MemberID` FROM `member` WHERE `Email` = '$username'"),0, 'MemberID');

            }
        function login ($username, $password) {
            $MemberID = user_id_from_username ($username);

            $username = sanitize($username);
            $password = md5($password);

            return (mysql_result(mysql_query("SELECT COUNT(`MemberID`) FROM `member` WHERE `Email` = '$username' AND `Password` ='$password'"), 0) == 1) ? $MemberID : false; }

在我的 login.php 中,我有:

Session_start ();
include 'core/functions/users.php'

if (empty($_POST) === false){
    $username = $_POST['Email'];
    $password = $_POST['Password'];


        $login = login($username, $password);
        if($login === 1){
            $_SESSION['MemberID'] = $login; //logged in and returned user ID and store in session
            header('location: member.php?username='.$username);

        }else{
            // try admin login
            $query2 = mysql_query("SELECT * FROM admin WHERE Email ='$username' AND Password ='$password'");
            if(mysql_num_rows($query2) == 1){
                $_SESSION['Email'] = $username;
                header("location: admin.php");
            }
            else{
                 echo "Failed Login Attempt"; 

            }
        }
    }

当我尝试登录用户时,出现此错误:

警告:mysql_result(): Unable to jump to row 0 on MySQL result index 8 in oddjobexchange\core\functions\user.php on line 27 Failed Login Attempt

我无法理解这个错误,因为我看不出第 27 行有什么问题(下)

return mysql_result(mysql_query("SELECT `MemberID` FROM `member` WHERE `Email` = '$username'"),0, 'MemberID');

在我的数据库中,“会员 ID”是第 0 行,“电子邮件”是第 7 行,“密码”是第 8 行。有人知道我做错了什么吗?

4

0 回答 0