0

I have been staring at this for 20 minutes now and I can't figure out what I'm doing wrong.

// Create query
$qry = "SELECT * FROM members WHERE member_id='"$_SESSION['SESS_MEMBER_ID']"'";
$result = mysql_query($qry);

Parse error: syntax error, unexpected T_VARIABLE in /home/dkitterm/public_html/test2/member-profile.php on line 24

6
  • I've edited your question, that is now the answer. Commented Dec 15, 2011 at 0:09
  • 3
    @Webarto I've rolled it back; that's not how editing works. Commented Dec 15, 2011 at 0:10
  • Then handle copy/pasta answers. Commented Dec 15, 2011 at 0:11
  • 1
    If only you were using placeholders ... you would have 1) avoided this error entirely, 2) have cleaner looking code, 3) stopped potential injection attacks. See stackoverflow.com/questions/60174/… Commented Dec 15, 2011 at 0:12
  • Dup: stackoverflow.com/questions/3401319/… Commented Dec 15, 2011 at 0:18

5 Answers 5

5

You need to concatenate the string literals with the variable with the . operator:

$qry = "SELECT * FROM members WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "'";
Sign up to request clarification or add additional context in comments.

Comments

1

You need to concatenate your string:

$qry = "SELECT * FROM members WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "'";

Comments

1

The less cumbersome approach is using string interpolation. You're already in a double quoted string, so why not utilize its one distinct feature?

$qry="SELECT * FROM members WHERE member_id='{$_SESSION['SESS_MEMBER_ID']}'";

That's terser and less room for syntax errors.
See also http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double (There's a shorter syntax even, if you read on.)

Comments

0

Change it to:

 //Create query
 $qry="SELECT * FROM members WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "'";
 $result=mysql_query($qry);

You forgot the concatenation operator, .

Comments

0
$qry="SELECT * FROM members WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "'";

You must concentrate your strings with . operator

Comments

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.