Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

coldfusion URL problem

Posted on 2004-03-26
7
Medium Priority
?
423 Views
Last Modified: 2013-12-24
Hi everyone, i need to learn coldfusion this weekend, ive started by converting my ASP code to Coldfusion..

<cfquery name="GetItems" datasource="#Request.MainDSN#">

<cfif #URL.brand# NEQ "" and #URL.all# NEQ "true">
Select * from parts where catid = #URL.catid# and brand = #URL.brand# order by brand
<cfelseif #URL.brand EQ# ""> 
Select * from parts where catid = #URL.catid# order by brand
</cfif>

</cfquery>
 i get this error Context validation error for tag cfif.. for people who know asp the original is below. Basically i want to choose which sql gets executed based on the URl..

if request.querystring("brand") <> "" and request.querystring("all") <> "true" then
set objRS = objDB.execute("Select * from parts where catid = " &request.querystring("catid")& " and brand = '" &request.querystring("brand")& "' order by brand")

else
set objRS = objDB.execute("Select * from parts where catid = " &request.querystring("catid")&" order by brand")
end if

Also if anyone has any coldfusion coding, something i can learn from, id really appreciate it if some could email me some code.. mrsigma@yahoo.com

Cheers
0
Comment
Question by:chizzy60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 12

Assisted Solution

by:jyokum
jyokum earned 400 total points
ID: 10693404
<cfif URL.brand NEQ "" and URL.all NEQ "true">
Select * from parts where catid = #URL.catid# and brand = #URL.brand# order by brand
<cfelseif URL.brand EQ ""> 
Select * from parts where catid = #URL.catid# order by brand
</cfif>


even better...

<cfquery name="GetItems" datasource="#Request.MainDSN#">
SELECT *
FROM parts
WHERE catid = <cfqueryparam value="#url.catid#" cfsqltype="cf_sql_varchar">
<cfif len(trim(url.brand)) and url.all neq 'true'>
AND brand = <cfqueryparam value="#url.brand#" cfsqltype="cf_sql_varchar">
</cfif>
ORDER BY brand
</cfquery>
0
 
LVL 11

Accepted Solution

by:
hart earned 600 total points
ID: 10693471
just a small change to jyokumz code [it will work] , but i think catid is numeric so

also use comparenocase to compare strings
also always use cfqueryparam, its a better coding practice and also improves site performance, as it acts as bind variables

<cfquery name="GetItems" datasource="#Request.MainDSN#">
SELECT *
FROM parts
WHERE catid = <cfqueryparam cfsqltype="cf_sql_numeric" value="#url.catid#">
<cfif len(trim(url.brand)) and ComapreNoCase(trim(url.all),'true') NEQ 0>
AND brand = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(url.brand)#">
</cfif>
ORDER BY brand
</cfquery>

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 10693481
sorry a small typo error n this line in my suggestion

change
ComapreNoCase(trim(url.all),'true') NEQ 0
to
CompareNoCase(trim(url.all),'true') NEQ 0

Regards
Hart
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 

Author Comment

by:chizzy60
ID: 10693562
thanks
one last thing
do you know why this
<OPTION VALUE="index.cfm?all=true&catid=#URL.catid#&brand=">All</OPTION>

gives me this

http://localhost/CF/index.cfm?all=true&catid=#URL.catid&brand=

ive also tried
#URLEncodedFormat(Trim(URL.catid))#

thanks
0
 
LVL 11

Expert Comment

by:hart
ID: 10693672
first of all don't send brand if its not required and in ur query

write
<cfif isDefined('form.brand') And len(trim(form.brand))>
and brand = blah blaj
</cfif>

secondly..

is your option inside a cfoutpot tag or not

what i mean is

<OPTION VALUE="index.cfm?all=true&catid=<cfoutput>#URL.catid#</cfoutput>">All</OPTION>

Regards
Hart



0
 

Author Comment

by:chizzy60
ID: 10693701
Thanks mate..
i kept getting
Element BRAND is undefined in URL
and i though brand= would be a way around..

thanks for the tips
thankyou
0
 
LVL 11

Expert Comment

by:hart
ID: 10693733
use IsDefined() to check wether a variable or form variables etc.. are defined or not

and have fun coding in cf, if any problem
you wkow where to find us ;-)

Regards
Hart
0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question