用php登录错误

时间:2018-03-16 16:08:11

标签: php mysql

我正在创建一个php登录系统。我无法理解问题所在。我试过谷歌,但我缺乏知识并不能让我理解问题所在。这是代码&错误。感谢

  

"注意:未定义的索引:密码在   第49行和第34行的D:\ xampp \ htdocs \ demo \ last_project \ includes \ server.php;

   if(isset($_POST['login'])) {
    $username = mysqli_real_escape_string($db, $_POST['username']);
    $password = mysqli_real_escape_string($db, $_POST['password']);

    // Ensure that form fields are filled properly
if(empty($username)) {
        array_push($errors, "Username is required!");
    }

if(empty($password)) {
        array_push($errors, "Password is required!");
    }
    if(count($errors) == 0){
        $password = md5($password); // Encrypt password before comparing this one with the one in database
        $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
        $result = mysqli_query($db, $query);
        if (mysqli_num_rows($result) == 1) {
        $_SESSION['username'] = $username;
        $_SESSION['success'] = "You are now logged in";
        header('location: ../system.php'); // Redirect to main page location
        } else {
            array_push($errors, "Wrong username/password combination");
                header('location: ../php/login.php');
        }
    }
}

0 个答案:

没有答案