PHP 嵌套引号
以下失败:
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$_SESSION['userID']'");
我尝试了以下操作:
$userID = $_SESSION['userID'];
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$userID'");
并且它有效。有没有办法在不创建单独变量的情况下做到这一点?
谢谢!
The following fails:
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$_SESSION['userID']'");
I tried the following:
$userID = $_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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
或者像这样:
Or like this:
或者
值得注意的是,它会推荐第一个,因为当您使用 php 编辑器时,它会更容易阅读/查找,这反过来又使调试更容易
or
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
您的第一个查询会阻塞,因为您实际上是在命令 WHERE
userID
is'$_SESSION['
。更不用说其余的userID']}'
将被 MySQL 解释为语法错误。Your first chokes the query, because you're actually commanding WHERE
userID
is'$_SESSION['
. Not to mentions that rest which isuserID']}'
will be interpreted as a syntax error by MySQL.是的,像这样
Yes, like this