I'm trying to get the current logged in users information from my Database. But when I run my code and log in as a trail user account it doesn't show their information but if i log into the user that is at the top of my database it shows their information. Example:
Bigfella account actually gets info from database ex: profile picture, description.
Beta account gets the profile picture, and description from the bigfella account
Heres my database table:
Heres my Code:
<?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 for the page:
<!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>
Any ideas on how I can fix this?? So its getting only the logged in users information? Thank You In advance!!
It looks like you might be able to run a query like this:
$stmt = $DB_con->prepare('SELECT id, username, description, userprofile FROM users WHERE id='.$_SESSION['user']['id']);