php - How Do I grab the User Id from database to display the profile for one single user when they are logged in?
I have a separate file 'login.php' for logging users into the website, which works perfectly. I have created another file 'loggedin.php' which will display the Logged In user's info from the database. The problem is that every user in the database has their info displayed because I can't find a way to connect the user's id to display this user's info alone using the "WHERE" statement. The entire code is like this.
<?php
reguire 'includes/dbh.inc.php';
$sql = "SELECT * FROM register WHERE registerId=?????";
$query = mysqli_query($conn,$sql);
$queryResult = mysqli_num_rows($query);
if($queryResult > 0){
while($row = mysqli_fetch_assoc($query)){
echo "<h4>Hello </h4>".$row['registerName'];
echo "<a href='profile.php'>Visit Your Profile</a>";
}
}else{
exit();
}
?>
I need help to be able to connect the Loggedin user's id so the page will display only the loggedin user's info.