I am trying to match the $username variable with the current session username (username of logged in account).
I am using the following code but getting a parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
$result = mysql_query("SELECT * FROM settings WHERE $username = $_SESSION['username']")
Three very obvious errors I see here:
$usernamein a query will be evaluated by PHP to the value of PHP’s$usernamevariable, which you apparently don’t have, which in turn evaluates it to “”.$_SESSION['username']should be quoted (“” or ”), because it’s evidently a string value.Moreover, I’d rewrite this as:
That being said, you don’t want to pass any variables from PHP directly to queries without sanitising them first. It’s an injection paradise.
[edit]
Also, seeing your error message the error is probably elsewhere. Unless you’re really missing the
;in the end of your line. Also, that error should give you exact PHP line number where the interpretation error occurred.