我正在尝试从我的数据库中获取当前登录的用户信息。但是,当我运行我的代码并以跟踪用户帐户登录时,它不会显示其信息,但如果我登录到数据库顶部的用户,则会显示其信息。例:
Bigfella帐户实际上从数据库ex获取信息:个人资料图片,描述。
Beta帐户获取个人资料图片,以及来自bigfella帐户的描述
继承我的数据库表:
继承我的代码:
<?php
include('functions.php');
if (!isLoggedIn()) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
require_once 'dbcon.php';
?>
<?php
$stmt = $DB_con->prepare('SELECT id, username, description, userprofile FROM users ORDER BY id DESC');
$stmt->execute();
if($stmt->rowCount() > 0)
{
$row=$stmt->fetch(PDO::FETCH_ASSOC);
extract($row);
}
?>
页面的HTML:
<!DOCTYPE html>
<html>
<head>
<title> Home</title>
</head>
<body>
<!-- logged in user information -->
<div class="profile_info">
<img src="uploads/<?php echo $row['userprofile']; ?>" class="img-rounded" width="250px" height="250px" />
<div>
<?php if (isset($_SESSION['user'])) : ?>
<strong><?php echo $_SESSION['user']['username']; ?></strong>
<small>
<i style="color: #888;">(<?php echo ucfirst($_SESSION['user']['user_type']); ?>)</i>
<br>
<a href="home.php?logout='1'" style="color: red;">logout</a>
</small>
<h4> Status: <?php echo $description ?> </h4>
<?php endif ?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
关于如何解决这个问题的任何想法?那么它只获取登录用户信息?先感谢您!!
您似乎可以运行如下查询:
$ stmt = $ DB_con-> prepare('SELECT id,username,description,userprofile FROM users WHERE id ='。$ _ SESSION ['user'] ['id']);