PHP不会重定向

时间:2017-02-27 19:00:08

标签: php mysql

所以我无法弄清楚我的PHP出了什么问题导致了这个问题。正如您从代码中看到的那样,我根据if语句对其进行了回显。如果细节等于查询,那么它将回显它所做的Test2。但为什么它没有重定向?我无法弄清楚出了什么问题。

<?php 
include "../inc/db.php";
include "../inc/functions.php";

$tip = "";

if(isset($_POST["submit"])) {
    $username = $_POST["username"];
    $password = $_POST["password"];

    $username = mysqli_real_escape_string($connection, $username);
    $password = mysqli_real_escape_string($connection, $password);

    $query = "SELECT * FROM users WHERE username = '{$username}' ";
    $select_user_query = mysqli_query($connection, $query);

    if(!$select_user_query) { 
        die("Query failed. Reason: " . mysqli_error($connection));
    }

    while($row = mysqli_fetch_array($select_user_query)) {
        $db_user_id = $row['id'];
        $db_username = $row['username'];
        $db_password = $row['password'];
    }

    if($username !== $db_username && $password !== $db_password ) {
        header("Location index.php");
        $tip = "Incorrect details!";
        echo "Test1";
    } elseif ($username == $db_username && $password == $db_password) {
        header("Location ");
        echo "Test2";
    } else {
        header("Location index.php");
        echo "Test3";
    }
}

?>

提交正确详细信息的结果: form01

并证明dashboard.php确实存在 help02

如果我输入mysql数据库中不存在的东西,那么我得到这个: help3

但是我在while循环中定义了变量

1 个答案:

答案 0 :(得分:0)

header("Location dashboard.php");

缺少半结肠

header("Location: dashboard.php");

我很蠢......