mysqlcoldfusioncfquerycfqueryparam

Error in my CFQUERYPARAM


I'm sure I'm just doing this horribly wrong with CFQUERYPARAM, but here's what I'm trying to do:

<CFQUERY DATASOURCE="tr3" NAME="qryPartner">
  SELECT *
  FROM  UsrMatchActualTR2
  WHERE 
    session = #userSess# 
   AND 
    user_id = #userID# 
   AND 
    site=<cfqueryparam value="#userSite#" cfsqltype="CF_SQL_VARCHAR" maxlength="5">
</CFQUERY>

And I'm receiving the error

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 'AND site='UTD'' at line 3


Solution

  • I suspect your userID variable is blank, causing a "hole" in your query structure. You should really use CFQUERYPARAM for all of your arguments, including userID and userSess.