0
votes

I am trying to setup $_SESSION data and echo it out onto the page. I am defining the sessions in the header

<?php

$users = $mysqli->query('SELECT * FROM fn WHERE username = '.$_SESSION['username']);
    if (is_object($users)) {
        if ($users->num_rows) {
            while ($row = $users->fetch_assoc()) {
                $first_name = $row['first_name'];
                $last_name = $row['last_name'];
                $email = $row['email'];
                $number = $row['number'];
                $region = $row['region'];
                $company = $row['company'];
                $level = $row['level'];
            }
        }
    }

$_SESSION['first_name'] = $first_name;

?>

I am then including the header.php file on my page and also using session_start();

I have no idea what im doing wrong.

I am managing to get the username and password to echo out... I assume its because it was added to the session upon login.

2
You must include the session start first before you can use it.Jeff Puckett
Also, the username is likely a string, so you'll need to wrap quotes around it. $mysqli->query("SELECT * FROM fn WHERE username = '".$_SESSION['username']."'");Qirel

2 Answers

1
votes

session_start() must come before you attempt to use $_SESSION variable, not after. Move your included file which contains session_start() to the top of that file for this to work.

0
votes

You need to add session_start(). Put it after your PHP start tag