0

I have a simple login for my site. When they login , a session variable is created

$_SESSION['username'] = $myemail;

On another page, i want to search through the database where email = the users email

 $sql = "SELECT * FROM work where Email = '.$_SESSION['Susername'].'  "; 

I am getting an error

Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) on that line

Also Subline Text 2 is highlighting the username in purple if that is any help ![enter image description here][1]

Can somebody spot some syntax error ?

Barry Burke
  • 94
  • 2
  • 13

1 Answers1

0

Your problem is you're trying to concatenate with . without actually exiting the current "double quotes", single quotes don't exit into "normal space" from within a double-quoted string.

Also, you should quote the value going into the SQL statement. Then, you should either have:

$sql = "SELECT * FROM work where Email = '{$_SESSION['username']}'";

Or otherwise:

$sql = "SELECT * FROM work where Email = '" . $_SESSION['username'] . "'";
Markus AO
  • 4,771
  • 2
  • 18
  • 29
  • You're welcome @BarryBurke. I prefer the first approach. I find it much more readable than constantly jumping in and out of quotes, gives my eyes a headache. – Markus AO Jun 27 '15 at 20:04