Moreover, the WHERE clause raises an error: you have an error in your SQL syntax;

Well. Whenever I try to get more than one WHERE clause, it just gives me a SQL syntax error.

Mistake:

Error Executing Database Query.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read = '0'' at line 3

Resources:
Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debug Output Settings, and select the Robust Exception Information option.
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser     Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Remote Address      ::1
Referrer    
Date/Time   21-Oct-14 08:27 PM

      

The SQL query itself:

<cfquery name = "getUserAlerts" datasource = "#DSN#">
SELECT *
FROM user_alerts
WHERE client_id = '#clientUser.id#' 
AND read = '0'
</cfquery>

      

There is nothing wrong with the SQL query in my opinion. And that should work, is there anyone who can see the error I posted? Or is it possible to give a correction?

Thanks in advance!

Edit:

Thanks for the quick answers you gave me. The reverse worked! Thanks guys!

+3


source to share


2 answers


The error is probably due to being READ

a reserved word
. Rename the column entirely (preferred) or remove it using backreferences.



As an aside, you should use cfqueryparam

query parameters for all variables. CFQueryparam offers a number of benefits (data type validation, improved query performance, etc.). One of the most important is preventing SQL injection, which can be a problem even with quoted strings .

+7


source


read

- reserved word: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

You will need to avoid this:



WHERE ...
 AND `read` = '1'
     ^----^--

      

Please note that these are backticks, not single quotes.

+4


source







All Articles