0

I'm using this code to try and display the user's id:

<?php    
    include("server.php");
    session_start(); 
    if (!isset($_SESSION['username'])) { 
        $_SESSION['msg'] = "You have to log in first"; 
        header('location: login.php'); 
    } 

    $username = $_SESSION['username'];
    $getID = "SELECT id FROM accounts WHERE username='{$_SESSION['username']}'";
    $getIDresults =  mysqli_query($conn, $getID);

?>

I can successfully use the session variable to create the query. However, when I try to echo the result, I'm left with the content of my page pushed down and the ID is not displayed.

This is the code being used to echo the result:

<p> 
    Welcome  
    <strong> <?php echo $getIDresults; ?> </strong>  
</p>

When replacing $getIDresults with $getID to view the query, I can see that the Session variable is populated correctly.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
ROD
  • 23
  • 4

0 Answers0