Reputation: 3
I am trying to query and display user information from the database such as name and email. I've spent a couple days on this and read some similar threads here but have had no luck.
If I use the following query I can get what I want about a specific user and display it accordingly.
$sql = "SELECT firstname, lastname, email FROM users where username = 'blim'";
Now I want to run the same query but replace 'blim' with ($_SESSION["username"]) I get an error.
$sql = "SELECT firstname, lastname, email FROM users where username = ($_SESSION["username"])";
The reason why I thought this would work is because by using
<?php echo ($_SESSION["username"]); ?>
I am able to display a greeting specif to the user logged in so I thought I could compare that to rows in the database to retrieve information from specific columns.
Upvotes: 0
Views: 123
Reputation: 732
Try loading the username from session into its own variable, then use that variable in the query.
$username = $_SESSION["username"];
$sql = "SELECT firstname, lastname, email FROM users where username = $username";
Upvotes: 1