我的PHP会话变量出了什么问题?

我的PHP会话变量出了什么问题?

问题描述:

I cannot get $userLabel ($_SESSION['nickname']) to print. I am using phpmyadmin with apache on a localhost.

I cannot seem to figure out to problem. I have the row made in phpmyadmin and I know it is in row 4. Could it be a wrong method or something? I am new to PHP and trying to best to figure it out. Any solutions or addition help would be great! Thank you!

login:

if($_POST['submit']) {
    include_once("connection.php");
    $username = strip_tags($_POST['username']);
    $password = strip_tags($_POST['password']);

    $sql = "SELECT id, username, password, nickname FROM users WHERE username = '$username' AND activated = '1' LIMIT 1";
    $query = mysqli_query($connect, $sql);

    if ($query) {
        $row = mysqli_fetch_row($query);
        $userId = $row[0];
        $dbUsername = $row[1];
        $dbPassword = $row[2];
        $userLabel = $row[4];
    }

    if ($username == $dbUsername && $password == $dbPassword) {
        $_SESSION['username'] = $username;
        $_SESSION['id'] = $userId;
        $_SESSION['nickname'] = $userLabel;


        header('Location: user.php');
    } 
    else {
        echo "Error: password mismatch.";
    }
}
?>
<html>
<head>
</head>
<body>
    <form action="index.php" method="post">
        <li>
            <input type="text" name="username" placeholder="Username">
        </li>
        <li>
            <input type="password" name="password" placeholder="Password">
        </li>
        <li>
            <input type="submit" name="submit" value="Sign In">
        </li>
    </form>
</body>
<html>

webpage:

if  (isset($_SESSION['id'])) {
    $userId = $_SESSION['id'];
    $username = $_SESSION['username'];
    $userLabel = $_SESSION['nickname'];
} 
else {
    header('Locaion: index.php');
    die();
}
?>
<html>
<head>
</head>
<body>
    <p><font color="white">Hello <?php echo $userLabel; ?>.</font></
</body>
<html>

<?php $userLabel = $row[3]; ?>

<p><font>Hello <?php echo $userLabel; ?>.</font></p>