Solved

coldfusion URL problem

Posted on 2004-03-26
7
406 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 100 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 150 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now