2015-08-20 35 views
-2
$raw_results = mysql_query("SELECT * FROM system_passwords 
    WHERE hide != 1 AND (`id` LIKE '%".$query."%') 
    OR (`system_name` LIKE '%".$query."%') 
    OR (`database_name` LIKE '%".$query."%') 
    OR (`username` LIKE '%".$query."%') 
    OR (`password` LIKE '%".$query."%') 
    OR (`notes` LIKE '%".$query."%') 
    OR (`additional_info` LIKE '%".$query."%')") or die(mysql_error()); 

如何或在哪裏添加隱藏!= 1到此?如何在我的select語句中添加WHERE hide!= 1?

+0

它已經存在,問題是什麼是什麼呢? – rlanvin

+0

它不工作的地方,所以我問它應該去哪裏,或如何寫它。 – deansmith

+0

不能正常工作,因爲在你得到一個錯誤或它不會給你你期望的結果? – chris85

回答

2

你要組orš在一起。正如您查詢運行爲

WHERE hide != 1 AND (`id` LIKE '%".$query."%') 

(system_name LIKE '%".$query."%') 

或等

值按預期這應該組。

SELECT * FROM system_passwords 
WHERE (
     (`id` LIKE '%".$query."%') OR 
     (`system_name` LIKE '%".$query."%') OR 
     (`database_name` LIKE '%".$query."%') OR 
     (`username` LIKE '%".$query."%') OR 
     (`password` LIKE '%".$query."%') OR 
     (`notes` LIKE '%".$query."%') OR 
     (`additional_info` LIKE '%".$query."%') 
    ) and hide != 1 

你也應該切換到PDOmysqli所以你可以使用準備好的語句。這可能會讓你打開SQL注入;不知道什麼$query不能肯定地說..

其他信息:Mysql or/and precedence?

+0

現在會拋出T_string錯誤 – deansmith

+0

不是來自剛剛粘貼的代碼。 https://eval.in/419960 – chris85

1

這是在正確的地方,但這是那麼模糊邏輯 WHERE hide != 1 AND ([a] OR [b] OR [c])

相關問題