解析错误:语法错误,意外的 T_IF [英] Parse error: syntax error, unexpected T_IF

查看:22
本文介绍了解析错误:语法错误,意外的 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"."
 FROM #__ezrealty AS a"."
 LEFT JOIN #__ezrealty_catg AS cc ON cc.id = a.cid"."
 LEFT JOIN #__ezrealty_locality AS dd ON dd.id = a.locid"."
 LEFT JOIN #__ezrealty_state AS ee ON ee.id = a.stid"."
 LEFT JOIN #__ezrealty_country AS ff ON ff.id = a.cnid"."
 LEFT JOIN #__ezrealty_profile AS ss ON ss.mid = a.owner"."
 LEFT JOIN #__users AS u ON u.id = a.checked_out".( count( $where ) ? "
 WHERE " . implode( ' AND ', $where ) : "").if ( isset ($_POST['idSearch']) ).{WHERE a.id =".$_POST['idSearch'] ;}."
 按"排序.$订单."
 LIMIT $pageNav->limitstart, $pageNav->limit";

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

解决方案

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

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

<预><代码>.( isset ($_POST['idSearch']) ? " WHERE a.id = " . $_POST['idSearch'] : '')

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

请注意,您真的应该查看您的代码,因为仅在我上面发布的代码中就有明显的 SQL 注入.任何人都可以在您的数据库上执行任意代码.确保清理您的输入,最好采用准备好的语句和参数化查询,以使您的代码更安全.

$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"

. "
 FROM #__ezrealty AS a"

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

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

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

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

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

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

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

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

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

. "
 ORDER BY ". $order

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

;

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

解决方案

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.

这篇关于解析错误:语法错误,意外的 T_IF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆