php - How Do I grab the User Id from database to display the profile for one single user when they are logged in?

197

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.

People are also looking for solutions to the problem: php - Why doesn't the ids of an Entity start incrementing at 1 during Fixtures loading?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.