1 Replies - 3947 Views - Last Post: 29 March 2012 - 05:44 AM Rate Topic: -----

#1 jk145   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-January 12

Unknown column 'Question' in field list

Posted 24 March 2012 - 10:53 AM

When executing the following code:
INSERT INTO ETrueFalseQuestions
	VALUES (<cfoutput>#newTypeID#</cfoutput>, `<cfoutput>#FORM.Question#</cfoutput>`, <cfoutput>#FORM.truefalse#</cfoutput>, `<cfoutput>#FORM.falsetext#</cfoutput>` );

I get the error message:

Unknown column 'Question' in 'field list'

The error occurred in /opt/railo/tomcat/webapps/ROOT/Testmaster/Application/Admin/addmyquestion.cfm: line 207

205: <cfquery name="qUpdateTheQuestion" datasource="testmaster">
206: INSERT INTO ETrueFalseQuestions
207: VALUES (<cfoutput>#newTypeID#</cfoutput>, `<cfoutput>#FORM.Question#</cfoutput>`, <cfoutput>#FORM.truefalse#</cfoutput>, `<cfoutput>#FORM.falsetext#</cfoutput>` );

The unknown column Question is actually the value of FORM.Question, and will change depending on what you enter into the form. I cannot figure out why it is looking for a column with that name.

Any suggestions would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Unknown column 'Question' in field list

#2 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: Unknown column 'Question' in field list

Posted 29 March 2012 - 05:44 AM

I'm not familiar with the specifics of Railo error messages but it seems like it's saying you don't have a form.question variable available. Try dumping the form scope to the screen (along with an abort) and see if you have form.question available.

That said, there's a few things I'd suggest insofar as your insert query goes:

It's good form to explicitly call the columns you're inserting data to in your database tables so that anyone else looking at your code later (who may not have access to the database) can tell what's going where. It's also helps in case someone modifies the database later (adding or dropping a column, for instance).

Also, you don't need to explicitly wrap each variable you're inserting in its own CFOUTPUT. Railo may be different in this regard but normally, CF automatically interprets a pounded value in a CFQUERY.

Last, I urge all CF folk to use the CFQUERYPARAM tag for any database interactions involving variables. In your case, where values are coming in from a form, use of that tag eliminates anyone trying a SQL injection attack against your database. The tag also tends to result in correctly formed data (often when dealing with dates/times for instance) and it'll even impart a little performance boost in most cases.

This post has been edited by Craig328: 29 March 2012 - 05:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1