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

查看:164
本文介绍了解析错误:语法错误,意外的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"

;

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

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

推荐答案

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'] : '') 

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

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

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

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天全站免登陆