Today I ran into a coding mistake that I wanted to blog about, incase I see it again later. I was using ColdFusion’s cfqueryparam tag to validate a query insert value. I got this error: “No parameters defined during prepareCall()”. I am using MySQL, and here is the code:
<cfquery name=“insertQry” datasource=“#myDSN#”>
insert tblanswers
(descr)
values
(‘<cfqueryparam cfsqltype=“cf_sql_varchar” maxlength=“100” value=“#form.answerSubmitted#”>‘)
</cfquery>
insert tblanswers
(descr)
values
(‘<cfqueryparam cfsqltype=“cf_sql_varchar” maxlength=“100” value=“#form.answerSubmitted#”>‘)
</cfquery>
At first I thought it was a problem with MySQL, and how I was using cfqueryparam, but when I compared it to similar code that works elsewhere, I didn’t see any difference. What I finally discovered was that I needn’t put the single quotes around the cfqueryparam tag. Apparently the single quotes aren’t needed because ColdFusion is sending the database a prepared value. I have done this before, but forgot. 🙂