|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
trouble with creating SQL statement from FORM
I am trying to create a form where you can select what will be searched from a drop down menu then enter some text.
Code:
<cfform name="Name" action="list.cfm" method="Post">
<CFSELECT NAME="field">
<OPTION VALUE="LastName" SELECTED>last name</OPTION>
<OPTION VALUE="FirstName" >first name</OPTION>
</CFSELECT>
<CFSELECT NAME="type">
<OPTION VALUE="1" SELECTED>is</OPTION>
<OPTION VALUE="2" >begins with</OPTION>
<OPTION VALUE="3" >contains</OPTION>
<OPTION VALUE="4" >ends with</OPTION>
<OPTION VALUE="5" >sounds like</OPTION>
</cfSELECT>
<CFINPUT TYPE="text" NAME="query">
<INPUT TYPE="submit" VALUE="search">
</cfform>
However, it isn't searching correctly. Can anyone see anything wrong with my code? Here is the SQL code: Code:
<cfif IsDefined("form.query")>
<cfquery name="All" datasource="Personnel">
<cfif #form.type# EQ 1>
<cfset case = "#form.field#"&" = "&"#form.query#">
<cfelseif #form.type# EQ 2>
<cfset case = "#form.field#"&" LIKE "&"#form.query#"&"%">
</cfif>
<cfoutput>
SELECT * FROM Directory
WHERE '#case#'
</cfoutput>
</cfquery>
</cfif>
|
|
#2
|
|||
|
|||
|
Do you have an example of what the generated SQL that is actually being executed looks like?
|
|
#3
|
|||
|
|||
|
If I remove the ticks (') around #case# in the <cfoutput>, i get this message:
Code:
Error Diagnostic Information ODBC Error Code = 07001 (Wrong number of parameters) [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. Hint: The cause of this error is usually that your query contains a reference to a field which does not exist. You should verify that the fields included in your query exist and that you have specified their names correctly. The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (70:1) to (70:43). Date/Time: 05/19/04 11:40:38 Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322) Remote Address: 206.176.95.126 HTTP Referrer: http://www.mitchelltech.com/cf/StaffFiles/list.cfm |
|
#4
|
|||
|
|||
|
What kiteless is asking is if you can output the SQL that is being generated based on your logic.
Try commenting out the query for now: <cfif IsDefined("form.query")> <!--- <cfquery name="All" datasource="Personnel"> ---> <cfif #form.type# EQ 1> <cfset case = "#form.field#"&" = "&"#form.query#"> <cfelseif #form.type# EQ 2> <cfset case = "#form.field#"&" LIKE "&"#form.query#"&"%"> </cfif> <cfoutput> SELECT * FROM Directory WHERE '#case#' </cfoutput> <!--- </cfquery> ---> </cfif> to see what the SQL statement looks like... |
|
#5
|
||||
|
||||
|
those aren't ticks (`), those are single quotes (')
they belong around string values, not WHERE conditions Code:
<cfset case = form.field
& " = '"
& form.query
& "'">
...
WHERE #case#
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > trouble with creating SQL statement from FORM |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|