Copy link to clipboard
Copied
Good morning I have a situation wherein during an insert into my database, the variable that I created from an cfif/cfset throws an error. Am I missing something? My code is below...
<cfset gradepoint =VAL('#fcnpoint#') + VAL('#attitudepoint#') +
VAL('#guestpoint#') + VAL('#contactpoint#') + VAL('#attendancepoint#')
+ VAL('#nspoint#') + VAL('#foidpoint#') + VAL('#otherpoint#')>
<cfif "#gradepoint#" GTE "-20.45" AND "#gradepoint#" LTE "11.1"><cfset
maingrade= 'F'></cfif>
INSERT INTO squadreport (squid, squgrade)
VALUES ('00', '#maingrade#')
</cfquery>
Copy link to clipboard
Copied
If the CFIF condition is not met, #maingrade# will not be set.
You could CFPARAM #maingrade#, but this will not address the issue, it will just prevent the error.
^_^
Copy link to clipboard
Copied
Wolfshade has hit the nail on its head. I would add the following. The code reads better as
<cfset gradepoint = val(fcnpoint) + val(attitudepoint) + val(guestpoint) + val(contactpoint) + val(attendancepoint) + val(nspoint) + val(foidpoint) + val(otherpoint)>
<cfif gradepoint GTE -20.45 AND gradepoint LTE 11.1>
<cfset maingrade = "F">
</cfif>
Copy link to clipboard
Copied
Agreed. I've never been a fan of using the hashmarks when not necessary.
To fix the issue, you need to cover all bases. You provided only one conditional, but I'm assuming you have more. But if the CF Server is throwing the error message "Variable undefined", then there is an open condition (or, more accurately, a lack of a default condition.)
<cfif gradepoint gte -20.45 AND gradepoint lte 11.1>
<cfset maingrade = "F">
<cfelseif gradepoint gt 11.1 AND gradepoint lte 41.1>
<cfset maingrade = "D">
<cfelseif gradepoint gt 41.1 AND gradepoint lte 72.2>
and so on, until
<cfelse>
<cfset maingrade = "A">
</cfif>
^_^