Solved

coldfusion URL problem

Posted on 2004-03-26
7
420 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 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 

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

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.

Question has a verified solution.

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

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
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…

734 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