Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用正确的凭据登录php失败_Php_Mysql_Mysqli_Login - Fatal编程技术网

使用正确的凭据登录php失败

使用正确的凭据登录php失败,php,mysql,mysqli,login,Php,Mysql,Mysqli,Login,我有一个项目,需要使用php和mySQL为给定场景创建一个系统。另一个要求是,它必须为不同的用户登录 在我的实现中,即使使用正确的凭据,它也无法进行身份验证。我正在使用mysqli实现这个功能。没有语法错误,字段名和输入的凭据都是正确的 有问题的代码(login.php): 您混合了不同的mysql api;你不能这样做。你在WHERE子句中也使用了错误的标识符限定符。你能稍微解释一下吗@弗雷德二世查阅副本 <?php session_start(); // Starting Se

我有一个项目,需要使用php和mySQL为给定场景创建一个系统。另一个要求是,它必须为不同的用户登录

在我的实现中,即使使用正确的凭据,它也无法进行身份验证。我正在使用mysqli实现这个功能。没有语法错误,字段名和输入的凭据都是正确的

有问题的代码(login.php):


您混合了不同的mysql api;你不能这样做。你在
WHERE
子句中也使用了错误的标识符限定符。你能稍微解释一下吗@弗雷德二世查阅副本
<?php
    session_start(); // Starting Session
    $error=''; // Variable To Store Error Message
    if (isset($_POST['submit'])) {
        if (empty($_POST['username']) || empty($_POST['password'])) {
            $error = "Please enter a username and password";
        } else {
        // Define $username and $password
        $username=$_POST['username'];
        $password=$_POST['password'];
        // Calls the 'connect.php' to connect to the database and select the database
        require 'db/connect.php'; 
        // To protect MySQL injection for Security purpose
        $username = stripslashes($username);
        $password = stripslashes($password);
        $username = mysql_real_escape_string($username);
        $password = mysql_real_escape_string($password);

        // SQL query to fetch information of registerd users and finds user match.
        $result = $db->query("SELECT * FROM `users` WHERE 'usr_pwd'='$password' AND 'usr_name'='$username'");
        if ($result->num_rows == 1) {
            $_SESSION['login_user']=$username; // Initializing Session
            header("location: test.php"); // Redirecting To Other Page
        } else {
            $error = "Username or Password is invalid";
        }
        mysqli_close($db); // Closing Connection
        }
    }
?>