PHP 嵌套引号

发布于 2024-10-06 05:15:10 字数 317 浏览 4 评论 0原文

以下失败:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

羞稚 2024-10-13 05:15:10

或者像这样:

$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '{$_SESSION['userID']}'");

Or like this:

$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '{$_SESSION['userID']}'");
情泪▽动烟 2024-10-13 05:15:10
$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '".$_SESSION['userID']."'");

或者

$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '{$_SESSION['userID']}'");

值得注意的是,它会推荐第一个,因为当您使用 php 编辑器时,它会更容易阅读/查找,这反过来又使调试更容易

$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

ら栖息 2024-10-13 05:15:10

您的第一个查询会阻塞,因为您实际上是在命令 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 is userID']}' will be interpreted as a syntax error by MySQL.

掩饰不了的爱 2024-10-13 05:15:10

是的,像这样

$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$_SESSION[userID]'");

Yes, like this

$result = mysql_query("SELECT * FROM Tasks WHERE UserID = '$_SESSION[userID]'");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文