thefollower Posted October 12, 2007 Share Posted October 12, 2007 Hey guys i have a query which is giving me an error to do with "white space"... not seen such an error before so not sure what exactly i am looking for to fix it... this is what my query is: $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION['Current_User']'"); // Fetch the row from the database if (!($row = mysql_fetch_assoc($GetLetters))) { $bounce = 1; } If ($bounce == 1){ header("Location: letterbox.php"); } This is the error im getting: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\readnewletters.php on line 3 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 12, 2007 Share Posted October 12, 2007 The problem is caused by this line: <?php $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION['Current_User']'"); ?> You can't have a quoted index within a double quoted string. Write that line either this way: <?php $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); ?> or this way <?php $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='" . $_SESSION['Current_User'] . "'"); ?> I prefer the later way myself. Ken Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 12, 2007 Share Posted October 12, 2007 You should use the later really. Otherwise you are using an undefined index. Whilst php can deal with this, you will get a notice if you've have error reporting set to include notices. Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 No, the first method works just fine. Array indexes don't need to be quoted when included in a double quoted string. The first method won't generate any error message the second method wouldn't. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 12, 2007 Share Posted October 12, 2007 Hmm, you learn something new every day. I didn't realise that you dont recieve an undefined constant notice if you use the first method inside a double quoted string. Quote Link to comment Share on other sites More sharing options...
thefollower Posted October 12, 2007 Author Share Posted October 12, 2007 well i changed it to the 3rd option and it works a treat thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.