ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 19th, 2004, 10:58 AM
bwedekin bwedekin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Dubai, UAE
Posts: 449 bwedekin User rank is Corporal (100 - 500 Reputation Level)bwedekin User rank is Corporal (100 - 500 Reputation Level)bwedekin User rank is Corporal (100 - 500 Reputation Level)bwedekin User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 22 h 49 m 44 sec
Reputation Power: 8
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>

Reply With Quote
  #2  
Old May 19th, 2004, 11:22 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,494 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 41 m 47 sec
Reputation Power: 45
Do you have an example of what the generated SQL that is actually being executed looks like?

Reply With Quote
  #3  
Old May 19th, 2004, 11:41 AM
bwedekin bwedekin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Dubai, UAE
Posts: 449 bwedekin User rank is Corporal (100 - 500 Reputation Level)bwedekin User rank is Corporal (100 - 500 Reputation Level)bwedekin User rank is Corporal (100 - 500 Reputation Level)bwedekin User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 22 h 49 m 44 sec
Reputation Power: 8
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

Reply With Quote
  #4  
Old May 19th, 2004, 11:54 AM
bfolger71 bfolger71 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Boston, MA
Posts: 47 bfolger71 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 34 sec
Reputation Power: 5
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...

Reply With Quote
  #5  
Old May 20th, 2004, 07:48 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,745 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 39 m 51 sec
Reputation Power: 870
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#
__________________
r937.com | rudy.ca

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > trouble with creating SQL statement from FORM


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway