帐户页面 - 显示帐户信息

Account page - Showing account information

您好,我正在尝试编写一个显示已登录用户信息的帐户页面。这是我目前所拥有的:

 <?php
    include 'housestyle.php';
    include 'connection.php';
    global $mysqli;
    ?>
    <style>
    h1
    {

        font-size: 27px;
    }
    </style>

    <h1>Your Account</h1>
    <?php
    $profile=$_SESSION['userlogged'];
    $query="SELECT * FROM Users WHERE Username=" . $profile . "";
    $result = $mysqli->query($query) or die($mysqli->error.__LINE__);

    $row = mysql_fetch_array($result);

    while($row = mysql_fetch_array($result)) {
    print_r($row);
    }
    ?>

$_SESSION['userlogged'];来自 loginsubmit.php:

<?php
session_start();
?>
<font face="ClearSans-Thin">
<font color="lightgray">

    <?php
    include 'connection.php';
    include 'loginform.php';
    ?>
    <center>
    <?php
    if (isset($_POST['submit'])) 
        {
        $user = $_POST['username'];

        $pass = $_POST['password'];

        $query = "SELECT COUNT(*) AS cnt FROM Users WHERE Username='" . mysqli_real_escape_string($connection, $user) . "' && Password='" . mysqli_real_escape_string($connection, $pass). "'";
        $result = mysqli_query($connection, $query);
        $row = mysqli_fetch_assoc($result);

        $queryadmin = "SELECT COUNT(*) AS cnt FROM Admin WHERE Username='" . mysqli_real_escape_string($connection, $user) . "' && Password='" . mysqli_real_escape_string($connection, $pass). "'";
        $resultadmin = mysqli_query($connection, $queryadmin);
        $rowadmin = mysqli_fetch_assoc($resultadmin);

        if ($row["cnt"] > 0) 
        {
            $_SESSION["userlogged"] =  $user;
            header("Location: homepage.php");
        } 
        else if ($rowadmin["cnt"] > 0 )
            {
                $_SESSION["adminlogged"] = $user;
                header("Location: homepage.php");
            }
        else 
        {
            echo 'Not a valid login';
        }
    }
    ?>
    </center>

所以我试图让它识别在登录和会话开始时输入的用户名,然后用它来 return 该行中的所有内容。我哪里错了?

在上面的脚本中你不做 session_start(),所以 $_SESSION 是空的。