I have created form where the values are taken from the form. I still get and an error when I put my form value in the statement. But when I run the statement separately it works but now when I combine it doesn't.

<cfif not isdefined("Form.frmpricerange")> 
    <cfset Form.frmpricerange = "N"> 
<CFQUERY NAME="stuff" DATASOURCE="xxxxxx">
Select * 
FROM (people LEFT JOIN Cities ON City = Cities.palce) LEFT JOIN Check ON people.Code = Check.Code
WHERE (((Check.Date)>=#9/6/2011# And (Check.Date)<>#8/31/2011#)
HAVING (((Deal)=Yes) AND ((Webpage)=1) AND ((Date)>=#9/6/2011#) AND ((Released)=Yes) AND ((People.Price) Between <cfif #Form.pricerange# eq 5000 ><cfoutput>1</cfoutput></cfif> AND 30000))
ORDER BY People.Price_from;
<form method="post" name="frmpricerange">

<select name="pricerange" id="pricerange"  style="height:19px">
				<option value="0">Search By Price Range</option>            
				<option value="5000">0 - 5 000</option>
        		<option value="10000">5 000 -10 000</option>
                <option value="20000">10 000 - 20 000</option>
                <option value="50000">20 000 - 50 000</option>
<input name="Check" type="submit" />

Please help scratching my head :-/

Recommended Answers

Can you paste the error message?

Jump to Post

All 4 Replies

Can you paste the error message?

Can you paste the error message?

It shows no message just says page not found I have checked everything the file is sitting on the section.but when I remove the between clause it seems to work
. could there be commas quotes I missed.

It shows no message just says page not found

If you're using IE, it's probably a badly worded error message. Turn off it's friendly error messages or you won't be able to view the real error

but when I remove the between clause it seems to work

That's because your code isn't generating a valid SQL statement. You're not doing anything when Form.pricerange# is NOT equal to 5000. So your sql is incomplete:

AND ((People.Price) Between {there should be something here})

WHERE (((Check.Date)>=#9/6/2011# And (Check.Date)<>#8/31/2011#)

But overall the query doesn't make sense. There's a lot of contradictory and redundant conditions. Let's step back and figure out what you're trying to do in plain english 1st. Then we can help you put it into SQL.

A few small tips:
- Don't use Access specific syntax for dates ie #9/6/2011# . It's not portable. Better to use cfqueryparam or CreateODBCDate instead.
- A HAVING clause is only needed for aggregates. You're not using any. So all of those conditions belong in the WHERE clause instead

<cfif not isdefined("Form.frmpricerange")>
<cfset Form.frmpricerange = "N">

Use <cfparam> instead. It does the same thing in a lot less code.

<cfparam name="Form.frmpricerange" default="N">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.