...

View Full Version : Syntax error (missing operator) in query expression



suzierthanyou
04-29-2009, 07:22 PM
I'm getting this error and I can't work out why!


<cfquery name="insertart" datasource="062105cs06sr">
INSERT INTO art (userid, artcat, arttitle, arturl, artdescription, artdatecreated, artkeyword)
values (#form.userid#, #form.artcat#, #form.arttitle#, #form.arturl#, #form.artdescription#, #form.artdatecreated#, #form.artkeyword#)
</cfquery>

This is a form to put an image into the database and add some information about it.

[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'http://newmedia.leeds.ac.uk/ug06/cs06sr/cf/images/suzierthanyoulabel.png'.

The error occurred in F:\wwwroot\ug06\cs06sr\cf\image-uploaded.cfm: line 13

11 : <cfquery name="insertart" datasource="062105cs06sr">
12 : INSERT INTO art (userid, artcat, arttitle, arturl, artdescription, artdatecreated, artkeyword)
13 : values (#form.userid#, #form.artcat#, #form.arttitle#, #form.arturl#, #form.artdescription#, #form.artdatecreated#, #form.artkeyword#)
14 : </cfquery>
15 : Record Inserted!



Hmmmm!

Gjslick
04-30-2009, 08:19 AM
Again, not a ColdFusion issue per se, but another database issue. The reason you're getting this error is because when inserting a value into a text field in the database, you need to surround the actual text to be inserted with single quotes. Your code should look like the following (which I have reformatted for clarity's sake):



<cfquery name="insertart" datasource="062105cs06sr">
INSERT INTO art (
userid,
artcat,
arttitle,
arturl,
artdescription,
artdatecreated,
artkeyword
) VALUES (
#form.userid#,
'#form.artcat#',
'#form.arttitle#',
'#form.arturl#',
'#form.artdescription#',
'#form.artdatecreated#',
'#form.artkeyword#'
)
</cfquery>
Note that I did not surround the userID field's value with single quotes, because it is (or at least should be) a number field. Only values for text fields must be surrounded by single quotes.

Hope that helps.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum