douliang9057 2014-11-17 18:25
浏览 18
已采纳

PHP登录以正确的用户名返回false?

I am trying to create a basic login form which would check the user input against the database and respond accordingly.

Here is the main if statement:

    if (isset($_POST['email'])) { //sets $email and $pw to what the user types
        $email = $_POST['email'];
        $pw = $_POST['pw'];

        $user_ID = login($db, $email, $pw);
        if ($user_ID) {
            $id = $user_ID->user_ID;
            echo "<p>$id Login success!</p>";
            header("Location: index.php?page=profile&id=$id");
            die();
        }else {
            echo "<p>Login Failed</p>";
            echo $email;
            echo $pw;
            echo $user_ID;
        }
    }

and the function:

    function login($db,$email, $pw) {
        $inc_pw = md5($pw);
        $sql = "SELECT user_ID FROM profile WHERE email = '$email' AND pw = '$inc_pw'";
        $result = $db->query($sql);
        return $result->fetchObject();
    }

At present it always returns false and therefor Login failed. As far as i can tell it is not properly comparing the email and pw with what’s in the database but i am not sure how to fix it.

Thanks in advance for your help :)

  • 写回答

1条回答 默认 最新

  • dongzhuxun5136 2014-11-18 13:05
    关注

    Turns out the problem was with my database. The function is searching for an encrypted (md5) password and the database contained only none encrypted password.

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

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像