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.
$sql = "SELECT firstname, lastname, email FROM users where username = '".$_SESSION["username"]."'";PHP Parse error: syntax error, unexpected '"', expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in. @MyNameIs comment should work.$sql = "SELECT firstname, lastname, email FROM users where username = '{$_SESSION['username']}";, which is only a slightly shorter version fo MyNameIs's comment. Array inside a string needs to be enclosed in{}. Also, don't forget the'you had around'blim'.