Solved

coldfusion URL problem

Posted on 2004-03-26
7
408 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. 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 : Go t…

911 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

23 Experts available now in Live!

Get 1:1 Help Now