School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,368 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,452 people online right now. Registration is fast and FREE... Join Now!




ColdFusion not reading my WHERE clause

 

ColdFusion not reading my WHERE clause

xheartonfire43x

6 May, 2009 - 05:28 AM
Post #1

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
I am adding a simple search feature to my company's call tracking system where they could either search for the client's company, name, email, or reference id. Also they can select either completed or uncompleted tasks. The query is no using the part that says whether or not to get completed tasks or not. I am guessing that it is because of all of my LIKE clauses.

CODE

    <cfquery name="getTickets" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
        SELECT * FROM worklist
        <cfif isDefined('completed')>
            WHERE completed = '#completed#'
        </cfif>
        AND fullname LIKE <cfqueryparam value="%#form.search#%">
        OR email LIKE <cfqueryparam value="%#form.search#%">
        OR clientID = <cfqueryparam value="#getClient.clientid#">
        OR uniqueid LIKE <cfqueryparam value="%#form.search#%">
        ORDER BY datecompleted,lastupdated
    </cfquery>


User is offlineProfile CardPM
+Quote Post


armyCoder

RE: ColdFusion Not Reading My WHERE Clause

6 May, 2009 - 08:04 AM
Post #2

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
QUOTE(xheartonfire43x @ 6 May, 2009 - 06:28 AM) *

I am adding a simple search feature to my company's call tracking system where they could either search for the client's company, name, email, or reference id. Also they can select either completed or uncompleted tasks. The query is no using the part that says whether or not to get completed tasks or not. I am guessing that it is because of all of my LIKE clauses.

CODE

    <cfquery name="getTickets" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
        SELECT * FROM worklist
        <cfif isDefined('completed')>
        WHERE completed = '#completed#'
        </cfif>
        AND fullname LIKE <cfqueryparam value="%#form.search#%">
        OR email LIKE <cfqueryparam value="%#form.search#%">
        OR clientID = <cfqueryparam value="#getClient.clientid#">
        OR uniqueid LIKE <cfqueryparam value="%#form.search#%">
        ORDER BY datecompleted,lastupdated
    </cfquery>



Try this instead:

CODE

    <cfquery name="getTickets" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
        SELECT * FROM worklist
        WHERE fullname LIKE <cfqueryparam value="%#form.search#%">
        <cfif isDefined('completed')>
        AND completed = '#completed#'
        </cfif>
        OR email LIKE <cfqueryparam value="%#form.search#%">
        OR clientID = <cfqueryparam value="#getClient.clientid#">
        OR uniqueid LIKE <cfqueryparam value="%#form.search#%">
        ORDER BY datecompleted,lastupdated
    </cfquery>


This post has been edited by armyCoder: 6 May, 2009 - 08:05 AM
User is offlineProfile CardPM
+Quote Post

armyCoder

RE: ColdFusion Not Reading My WHERE Clause

6 May, 2009 - 08:10 AM
Post #3

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
Actually, doesn't at least one constant have to be true?

See this post: http://www.dreamincode.net/forums/showtopic93747.htm


CODE

<cfquery name="getTickets" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
SELECT * FROM worklist
WHERE somevalue=1
AND
(
fullname LIKE <cfqueryparam value="%#form.search#%"> OR
email LIKE <cfqueryparam value="%#form.search#%"> OR
clientID = <cfqueryparam value="#getClient.clientid#"> OR
uniqueid LIKE <cfqueryparam value="%#form.search#%">
)
<cfif isDefined('completed')>
AND completed = '#completed#'
</cfif>
ORDER BY datecompleted,lastupdated
</cfquery>


This post has been edited by armyCoder: 6 May, 2009 - 08:12 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 08:54PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month