PDA

View Full Version : SQL/Coldfusion radio button problem.....


Clark_Kent
07-19-06, 02:12 PM
Hey Everyone,

I have a form which contains three radio buttons and each one of those radio buttons has a value that needs to be assigned to three fields in a database. I'm using coldfusion and MySQL. So far my radio buttons act like they should, only problem is when i submit the form (which will update the database), coldfusion gives me an error which states the following:

"Syntax error or access violation message from server: "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 'WHERE carModelID=' at line 146"

Here is the lines of code the error points to...

245 : carOffline = 1
246 : </cfif>
247 : WHERE carModelID=#FORM.carModelID#</cfquery>
248 : <cflocation url="/admin/cars/index.cfm">
249 : </cfif>

I have implemented a <cfif> selection structure to assign the appropriate value to its corresonding radio button, in the lines of code above it starts with line number 245, the following code is all the lines before that which i implemented...

, <cfif FORM.radioGroup EQ 'online'>
online = 1,
carDeleted = 0,
carOffline = 0,
<cfelseif FORM.radioGroup EQ 'carDeleted'>
online = 0,
carDeleted = 1,
carOffline = 0,
<cfelseif FORM.radioGroup EQ 'carOffline'>
online = 0,
carDeleted = 0,
carOffline = 1
</cfif>
WHERE carModelID=#FORM.carModelID#</cfquery>

And lastly, here are the input tags for the radio buttons...

<input type="radio" name="radioGroup" value="carDeleted" <cfif (#rsCarModel.carDeleted# EQ 1)>checked</cfif>>

<input type="radio" name="radioGroup" value="carOffline" <cfif (#rsCarModel.carOffline# EQ 1)>checked</cfif>>

<input type="radio" name="radioGroup" value="online" <cfif (#rsCarModel.online# EQ 1)>checked</cfif>>

The error states there is something wrong with line of code with the WHERE clause, i can't see anything wrong with it, i'm assuming something before it is whats causing the problem.... can anybody see whats wrong with any of the syntax?

Thanks for your help,

- CK

Clark_Kent
07-19-06, 05:43 PM
No worries, i found the problem.

Here lied the problem...

, <cfif FORM.radioGroup EQ 'online'>
online = 1,
carDeleted = 0,
carOffline = 0,
<cfelseif FORM.radioGroup EQ 'carDeleted'>
online = 0,
carDeleted = 1,
carOffline = 0,
<cfelseif FORM.radioGroup EQ 'carOffline'>
online = 0,
carDeleted = 0,
carOffline = 1
</cfif>
WHERE carModelID=#FORM.carModelID#</cfquery>

The commas in bold aren't supposed to be there.

I hope this helps someone :),

- CK