How do I call a registered session variable. in a select statement...
<?php $sql=mysql_query("SELECT * FROM table WHERE uid = ".$_SESSION['uid']." ") ?>
This errors... Should I predefined the variable?
Try this: $sql=mysql_query("SELECT * FROM table WHERE uid = \"".$_SESSION['uid']."\" ");
You had no quotes around it, and often the session ID has characters as well as numbers.
Originally posted by Mordecai Try this: $sql=mysql_query("SELECT * FROM table WHERE uid = \"".$_SESSION['uid']."\" "); You had no quotes around it, and often the session ID has characters as well as numbers.
I didn't really mean the session ID ... I meant a regestered variable (in this case the user id)
Should I note be using quotes at all ?
I do know that ' $_SESSION['uid']' doesn't work either...
Help.
Have you done a session_start()?
Are you sure the $_SESSION element you're trying to access has been defined somewhere along the way in your session?
Try doing a print_r($_SESSION) somewhere in your pages to track down what's happening.
Andy.
Originally posted by plaggypig Have you done a session_start()? Are you sure the $_SESSION element you're trying to access has been defined somewhere along the way in your session? Try doing a print_r($_SESSION) somewhere in your pages to track down what's happening. Andy.
Yes indeed... The session IS started and I am printing the regestered variable just above the select stmt. ... so I know it's there...
ALL I am trying to find out is what is the correct syntax to call registered session variable in a sql select statement.
the answer to your question would be:
$sql = mysql_query("SELECT * FROM table WHERE uid = '" . $_SESSION['uid'] . "'");
Most of the queries that I do is usually of the format select * from Users where Uname='".$SESSION['USER']."'" and they seem to work? At first I used to grab the session variable from the $GLOBALS array, but the $SESSION array seems to work more efficiently as far as coding goes🙂
That did work... I appreciate your help and that of all.