View Full Version : using session variables in mysql queries

07-02-2007, 02:19 AM
My php code consists of getting a person's session_id() and placing that in a session variable for use in other pages.
The thing is, though, that when i place a session variable in a mysql query, i get the following error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/e/r/i/ericjacobson01/html/index.php on line 11

This is the part that php complains about:

$_SESSION['buyer_id'] = session_id();

$istableset = mysql_query("SELECT * FROM ' .$_SESSION['buyer_id'] '");

07-02-2007, 02:39 AM
$_SESSION['buyer_id'] = session_id();

$istableset = mysql_query("SELECT * FROM ' .$_SESSION['buyer_id'] . '");

missing "." (concatenation operator)

07-02-2007, 02:44 AM
$istableset = mysql_query("SELECT * FROM {$_SESSION['buyer_id']}");

07-02-2007, 02:46 AM
oops. you're right, of course.

07-02-2007, 02:48 AM
lol :) i try, i didnt mean to sound rude by saying you were wrong its just i got other things to do and really did Post a quick reply

07-02-2007, 02:51 AM
I didn't take it as rude, you were right, I was out in left field - guess I should have actually read the line before I tried to debug it.