Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using html form to input values from SQL query's Where Clause

Status
Not open for further replies.

larryman

Programmer
Jun 16, 2000
63
US
Please, I need help urgently.<br>I'm a beginner with ColdFusion. I have a website am developing with coldfusion. Pls can anybody tell me how to use html form Input variable values in my SQL query's Where Clause?<br>Example<br>Say I have a form with an input text book &quot;NAME&quot;<br>The user types in &quot;BIOLA&quot; as his name.<br>I want to query my database to see if I have a user called &quot;BIOLA&quot;.<br>I did something like this<br>&lt;CFQUERY NAME=bbb DATASOURCE=&quot;ccc&quot;&gt;<br>Select Name From Table Where Name='#Form.Name#'<br>&lt;/CFQUERY&gt;<br>But i got an error message saying column does not exist or something like that. PLS i need help URGENTLY
 
Your query should work based on your post.<br><br>First thing I would check is that your datasource is connected correctly (The error message would indicate that it is).<br><br>Your example looks like your just showing us the form of your query, so the first thing I would think of in this case is: Does your table name or column name have any spaces in them?&nbsp;&nbsp;Microsoft Access (and maybe other databases) allows this, but CF will choke on a query like &quot;select my column from my table where my column ='#form.name#'&quot;. (I learned this the hard way..:)<br><br>Another thing to check for, and is VERY common, could be just a simple typo. <br>Try this:<br><FONT FACE=monospace><br>&lt;CFQUERY NAME=&quot;bbb&quot; DATASOURCE=&quot;ccc&quot;&gt;<br>Select * From Table<br>&lt;/CFQUERY&gt;<br>&lt;cfoutput&gt;#bbb.ColumnList#&lt;/cfoutput&gt;<br></font><br>this will give you a list of column names as CF is reading them.<br><br>One more thing could be that you may be using a reserved word as a table or column name.&nbsp;&nbsp;Check your database help file for a list of reserved words and don't use them as object (table,column,view, etc.) names.&nbsp;&nbsp;That'll avoid a lot of trouble.<br><br>Let me know if this helps.&nbsp;&nbsp;If not, post the actual code you're using and I'll see what I can do.&nbsp;&nbsp;If so, let me know which fix did it.<br><br>DM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top