Skip to main content
Inspiring
October 19, 2009
Question

Single quotes in an evaluate expression

  • October 19, 2009
  • 1 reply
  • 1040 views

I need to evaluate a variable which is itself a variable

<cfset val="form.avis_#form.mod_eval#">


<cfset coment="#evaluate(val)#">

Then my variable "coment" contains "single quotes",

then this Query bugs, as the single quote is interpreted by SQL as end of value.

  <cfquery name="upd_eval" datasource="#stw_article#">
   update mar_evaluation
   set eval_coment='#preservesinglequotes(coment)#'
   where eval_id=#form.mod_eval#
  </cfquery>

I tried also this :

<cfset val="form.avis_#form.mod_eval#">
  <cfquery name="upd_eval" datasource="#stw_article#">
   update mar_evaluation
   set eval_coment='#evaluate(val)#'
   where eval_id=#form.mod_eval#
</cfquery>

Same the SQL bugs,

so how to pass single quotes in the evaluate variable ?

For the momentI had to replace single quotes by blanc space to avoid he bug.

Thanks fo answers.

Pierre.

This topic has been closed for replies.

1 reply

Inspiring
October 19, 2009

I need to evaluate a variable which is itself a variable

<cfset val="form.avis_#form.mod_eval#">

No, you do not need evaluate. Simply use associative array notation:

ie ]]>

where eval_id=#form.mod_eval#

Also, always look into cfqueryparam. It should be used on all user supplied values. Especially with databases capable of executing multiple statements.

Inspiring
October 19, 2009

Good answer, but the syntax for the example is incorrect.  You want something like,

form["constant_part" & variable_part]

Inspiring
October 19, 2009

Ugh. Is there some special trick to posting code, when replying via email?  Apparently the forum removed my code sample:

<cfset theValue = FORM["baseName_"& dyanmicPart]>
ie <cfset theValue = FORM["avis_"& form.mod_eval]>