2016-03-19 74 views
0
foreach ($checkArray as $key => $value) { 

    $deleteUserStmt=$user_home->runQuery("DELETE FROM users WHERE userID = '".$key."' " AND " '".$value."'=1"); 

$deleteUserStmt->execute(); 
} 

我得到錯誤:MySql查詢:DELETE FROM。語法錯誤或訪問衝突:1064

Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1' at line 1

$ checkArray $關鍵是用戶ID和值是真還是假。 RunQuery方法與其他查詢一起工作。

所以我認爲我有查詢語法的問題?

+0

呼應一下,看看;像$ del =「DELETE FROM .....」; echo $ del; – rahul

+0

僅僅通過語法高亮'$ key。「'」AND「'應該告訴你關閉了......假設你已經注意到了這個代碼的SQL注入 – chris85

+0

爲什麼有人會爲列添加單引號shouldn' t是'column_name'的一個tilda – rahul

回答

0

查詢應該是這樣的,不要把單引號的列名:
"DELETE FROM users WHERE userID = '$key' AND $value='1'"

+0

感謝它的工作。 – Darius92

相關問題