1 Replies - 3941 Views - Last Post: 21 May 2012 - 05:44 AM Rate Topic: -----

#1 iggy407  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-January 11

query search error and relative path

Posted 18 May 2012 - 05:04 PM

As I am teaching myself coldfusion by reading Ben Forta books and creating a website i am having 2 simple problems that I can seem to resolve the first is I have a search page that works correctly but if a user types in the search page address without using the search form the query throws an error it mainly says "element URL.bedroo is undefined in the URL " is there some code or method that i can use to allow the page to continue without an error .

<cfinclude template="masterfile/master.cfm">

<div align="center">
<cfquery name="iam" datasource="wildlife" cachedafter="7-4-2012">
SELECT user_id,askingprice FROM re_owner
WHERE bedroom = <cfqueryparam value="#URL.bedroo#">
   AND    bathroom = <cfqueryparam value="#URL.bathroo#">
</cfquery>
<cfoutput query="iam">#user_id# #askingprice#<br /></cfoutput>


</div>
<cfinclude template="footer.cfm">




and the 2nd issue is finding out how I can use all my links correctly as I have some in sub-folders and the links from the root to subfolder causes an error i have tried something like this but it doesnt work..

<cfset links= expandpath("\")>
<a href="#links#mywebsite.com">My link</a>




Is This A Good Question/Topic? 0
  • +

Replies To: query search error and relative path

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1912
  • View blog
  • Posts: 3,444
  • Joined: 13-January 08

Re: query search error and relative path

Posted 21 May 2012 - 05:44 AM

Quote

if a user types in the search page address without using the search form the query throws an error it mainly says "element URL.bedroo is undefined in the URL " is there some code or method that i can use to allow the page to continue without an error .


There are two ways to handle that. One is to wrap your query (or even just the portions of the where statement containing references to the variables) in a CFIF block that checks for the existence of variables you're using in the query. If they don't exist then the code within them doesn't execute.

The other way is to set your page up to have default variables which are then sometimes overwritten depending upon the circumstances. For that you would use a CFPARAM tag, normally at the top of your page.

Give that a look and you should be on your way with problem 1.

Your second issue is just a pathing issue. Whenever I have trouble with stuff like that, I'll temporarily output the path the app is producing and then manually try and go to that URL to see if it's accurate. If it's not, I fix it. Recheck how to use ExpandPath() and see if it's doing what it is you expect it to do. Try outputting the result of the ExpandPath() out to the browser for a moment and check what it's spitting out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1