The following fails:
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$_SESSION['userID']'");
I tried the following:
$us开发者_开发知识库erID = $_SESSION['userID'];
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$userID'");
and it works. Is there a way to do this without making a separate variable?
Thanks!
Or like this:
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '{$_SESSION['userID']}'");
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '".$_SESSION['userID']."'");
or
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '{$_SESSION['userID']}'");
worth noting it would recommend the first one because it gets easier to read/find when you use a php editor, which in return makes it easier to debugg
Your first chokes the query, because you're actually commanding WHERE userID
is '$_SESSION['
. Not to mentions that rest which is userID']}'
will be interpreted as a syntax error by MySQL.
Yes, like this
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$_SESSION[userID]'");
精彩评论