I want to display the amount from the table user to the user's dashboard for logged in users only

<?php echo $_SESSION['username']; ?>

This code displays the username of the user currently logged in.

I want to display the “amount” in the same table as the “username” but it doesn’t work.

I tried <?php echo $_SESSION['amount']; ?>
And it didnt work.

Please, I need your help.

What does “it didn’t work” mean? Did you get an error message, and if so, what did it say? Does that session variable exist at the point that you want to display it?

I didn’t get an error message, it just didn’t display anything.
While on the place where this code is, <?php echo $_SESSION['username']; ?> it displays the Logged in user’s username.

Put this at the beginning of your code

ini_set('display_errors', 1);

Alright. Ill do that and share what i get here.

In case it is not clear, session keys i.e. $_SESSION['username'] will only be set when it is defined and only hold a value when it has been assigned to this key.

You could say $_SESSION['username'] = ''; means the key 'username' has been set to session but has no value.

If you find the login code, you will probably find something like $_SESSION['username'] = $row['username']; , where a database query result sets user details to session.

It would be in this query where you would make sure the amount field is called and set $_SESSION['amount'] = $row['amount]; in the way that $_SESSION['username'] is defined.

Note: I would not set any user login information to session but instead set their id to session so it can be used to query the database and usually (if needed) some kind of permission value e.g. Admin/user then also maybe some name value if it is going to be displayed like their full name.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.