0

I am trying to select data from specific user in MySQL database to PHP using my session. Code I have is:

$sql = "SELECT * FROM users WHERE Username = "$_SESSION['sess_user']" LIMIT 1";

I'm currently getting this error

Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE)

0

4 Answers 4

4

Since we're more than likely dealing with a string, you would need to add quotes to it and concatenate it with dots/periods.

I.e. '".$_SESSION['sess_user']."'

Just to be 100% certain, make sure you have started the session using session_start(); at the top of every page using sessions.

Sign up to request clarification or add additional context in comments.

1 Comment

Use a prepared statement
2

just use ' instead of "

$sql = "SELECT * FROM users WHERE Username = '{$_SESSION['sess_user']}' LIMIT 1";

1 Comment

Use a prepared statement
0

You are missing the . (DOT) symbol for adding variables to strings. Try this:

$sql = "SELECT * FROM users WHERE Username = " . $_SESSION['sess_user'] . " LIMIT 1";

That's it.

1 Comment

Use a prepared statement
0

i had the same issue

i just had to give my variable a name and use that

$sessUser = $_SESSION['sess_user'];

then use $sessUser in your sql statement

1 Comment

Use a prepared statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.