解析错误:语法错误,意外的 T_IF

发布于 2024-12-22 08:41:47 字数 864 浏览 3 评论 0原文

$query = "SELECT a.*, cc.name AS category, dd.ezcity AS proploc, ee.name AS statename, ff.name AS cnname, ss.dealer_name AS propseller, u.name AS editor"

. "\n FROM #__ezrealty AS a"

. "\n LEFT JOIN #__ezrealty_catg AS cc ON cc.id = a.cid"

. "\n LEFT JOIN #__ezrealty_locality AS dd ON dd.id = a.locid"

. "\n LEFT JOIN #__ezrealty_state AS ee ON ee.id = a.stid"

. "\n LEFT JOIN #__ezrealty_country AS ff ON ff.id = a.cnid"

. "\n LEFT JOIN #__ezrealty_profile AS ss ON ss.mid = a.owner"

. "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"

. ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : "")

. if ( isset ($_POST['idSearch']) ) 

    . { " WHERE a.id = " . $_POST['idSearch']  ; }

. "\n ORDER BY ". $order

. "\n LIMIT $pageNav->limitstart, $pageNav->limit"

;

我在这里没有得到错误的语法:(,,并且它不断返回相同的错误意外 T_IF

$query = "SELECT a.*, cc.name AS category, dd.ezcity AS proploc, ee.name AS statename, ff.name AS cnname, ss.dealer_name AS propseller, u.name AS editor"

. "\n FROM #__ezrealty AS a"

. "\n LEFT JOIN #__ezrealty_catg AS cc ON cc.id = a.cid"

. "\n LEFT JOIN #__ezrealty_locality AS dd ON dd.id = a.locid"

. "\n LEFT JOIN #__ezrealty_state AS ee ON ee.id = a.stid"

. "\n LEFT JOIN #__ezrealty_country AS ff ON ff.id = a.cnid"

. "\n LEFT JOIN #__ezrealty_profile AS ss ON ss.mid = a.owner"

. "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"

. ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : "")

. if ( isset ($_POST['idSearch']) ) 

    . { " WHERE a.id = " . $_POST['idSearch']  ; }

. "\n ORDER BY ". $order

. "\n LIMIT $pageNav->limitstart, $pageNav->limit"

;

i don get the wrong syntax here :( ,, and it keep return the same error unexpected T_IF

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

寻梦旅人 2024-12-29 08:41:47

删除 . (点)在 if 语句之前。因为 if 语句本身不是字符串,所以您不能只是将其连接起来。

Remove the . (point) before the if-statement. Because the if-statement itself isn't a string you can't just concatenate it.

鸠魁 2024-12-29 08:41:47

不要这样做:

. if (condition) { value_if_true; }

而是这样做:

. (condition ? value_if_true : value_if_false)

Don't do this:

. if (condition) { value_if_true; }

Instead do this:

. (condition ? value_if_true : value_if_false)
随梦而飞# 2024-12-29 08:41:47

if 只能是一个语句:您将其用作 表达式。它不返回任何内容,并且不能在另一个语句中使用。

但是,您可以使用三元运算符来执行此操作:

. ( isset ($_POST['idSearch']) ?  " WHERE a.id = " . $_POST['idSearch'] : '') 

这表示“如果设置了 $_POST['idSearch'],则添加该字符串,否则,添加空字符串。

请注意,您应该仔细看看你的代码,因为我上面发布的代码中存在明显的 SQL 注入,任何人都可以在你的数据库上执行任意代码,并且最好采用准备好的语句和参数化查询。让你的代码更安全。

if can only ever be a statement: you are using it as an expression. It doesn't return anything, and it cannot be used within another statement.

You can, however, use the ternary operator to do exactly this:

. ( isset ($_POST['idSearch']) ?  " WHERE a.id = " . $_POST['idSearch'] : '') 

This says "if $_POST['idSearch'] is set, add that string, otherwise, add the empty string.

Note that you should really look at your code, because there is a glaring SQL injection in just the code that I've posted above. Anyone could execute arbitrary code on your database. Make sure to sanitise your input and, preferably, adopt prepared statements and parameterised queries to make your code more secure.

情何以堪。 2024-12-29 08:41:47

我相信你想把它变成一个邪恶三元运算符:

. (count ...)
. (isset($_POST['idSearch']) ? ' WHERE a.id = ' . $_POST['idSearch'] : '')
. "\n ORDER BY" ...

I believe you want to turn this into an evil ternary operator:

. (count ...)
. (isset($_POST['idSearch']) ? ' WHERE a.id = ' . $_POST['idSearch'] : '')
. "\n ORDER BY" ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文