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.

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

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型