Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

coldfusion URL problem

Posted on 2004-03-26
7
Medium Priority
?
425 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
  • 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

927 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