'How do i display the username who posted the comment?

So far I am only able to display the username who is logged in at the moment, therefore, all the comments will be posted by the username who is logged in at the moment :(

if (isset($_SESSION['username'])) {
  echo '<div class="media my-3">
    <img src="img/userprofile.png" width="54px" class="mr-3" alt="...">
    <div class="media-body">
      <p class="font-weight-bold my-0">'.$_SESSION['username'].' at '. $thread_time.'</p>
      <h5 class="mt-0">
        <a class="text-dark" href="thread.php?threadid=' . $id . '">'. $title .'</a>
      </h5>
      '. $desc .'
    </div>
  </div>';
} 


Solution 1:[1]

i think your using a username session value who is logged in....you need to to save the userId in the table while submitting the comments form and use the userId to show the username.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pk_