doubo4824 2015-10-20 06:34
浏览 13
已采纳

我的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>
  • 写回答

1条回答 默认 最新

  • duanhuanzhi6431 2015-10-20 06:37
    关注
    <?php $userLabel = $row[3]; ?>
    
    <p><font>Hello <?php echo $userLabel; ?>.</font></p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址