Reputation: 7
How do I select a value from a database where username is based on the session?
This is what I have so far:
$query = mysql_query ("select id from CUSTOMER where username = .$_SESSION['username'] ");
Upvotes: 0
Views: 13422
Reputation: 31910
Session variable in your query wasn't parsed properly. You could fix it using curly bracers syntax:
$query = mysql_query( "select id from CUSTOMER where username = '{$_SESSION[ "username" ]}'" );
or concatenate it using dot operator:
$query = mysql_query ( "select id from CUSTOMER where username = '" . $_SESSION[ "username" ] . "'" );
You can find more about parsing strings in PHP manual.
Upvotes: 1
Reputation: 2063
$query = mysql_query("select id from CUSTOMER where username = '".$_SESSION['username']."'");
Upvotes: 1
Reputation: 36611
If username is in session cookie then grab the username like this
$username = $_SESSION['username'];
$escuname = mysql_real_escape_string($username);
$query = mysql_query("select id from CUSTOMER where username = '".$escuname."' LIMIT 1");
Upvotes: 3