Eiolon Posted August 29, 2007 Share Posted August 29, 2007 Here is what I am trying to do: When a user logs in, a session variable is passed. The variable is the users ID. If the variable is passed successfully, they are logged in and I want to query the users information based on the session variable. <?php # main.php // Start the session. session_start(); // Check for the session value. if (isset($_SESSION['id'])) { // Query database for user information. $query = "SELECT username, firstname, lastname FROM users WHERE id = '.$_SESSION['id'].'"; $result = mysql_query ($query) OR die ('Cannot execute the query.'); $auth = mysql_fetch_array ($result); } else { // Quit the script and redirect to login page. header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname ($_SERVER['PHP_SELF']) . "index.php"); exit(); } ?> Here is the error I am receiving: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\main.php on line 10 I can get this to work if I create and pass a variable for each piece of user info during the login process but I thought it would be easier to pass the users ID and just query their info from there. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/67231-solved-trying-the-query-user-info-from-a-session-variable/ Share on other sites More sharing options...
DJTim666 Posted August 29, 2007 Share Posted August 29, 2007 Replace this; $query = "SELECT username, firstname, lastname FROM users WHERE id = '.$_SESSION['id'].'"; With this; $query = "SELECT username, firstname, lastname FROM users WHERE id = ".$_SESSION['id'].""; That should work. Whenever you are using ' . . ', don't use single quotes( ' ), use double quotes( " ). Hope that works/helps. -- DJ Link to comment https://forums.phpfreaks.com/topic/67231-solved-trying-the-query-user-info-from-a-session-variable/#findComment-337234 Share on other sites More sharing options...
Eiolon Posted August 29, 2007 Author Share Posted August 29, 2007 That appears to have solved it. Thanks! Link to comment https://forums.phpfreaks.com/topic/67231-solved-trying-the-query-user-info-from-a-session-variable/#findComment-337258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.