Detail page element undefined

I am creating a web-site that features a detail page which is supposed to display whenever a user clicks on a hyperlink in a results page posted from a search query

Here is the code from the detail page

<cfquery name="details" datasource="#Request.dsn#">
SELECT *
FROM MLS
LEFT OUTER JOIN TblPicPaths
ON TblPicPaths.mlsid = mls.mlsid
WHERE MLS.mlsid= #url.mlsid#
</cfquery>

When I click on the hyperlink on the results page I get this error

Element MLSID is undefined in URL.
The error occurred in D:\Hosting\lairson\detail_page.cfm: line 6
 
4 : LEFT OUTER JOIN TblPicPaths
5 : ON TblPicPaths.mlsid = mls.mlsid
6 : WHERE MLS.mlsid= #url.mlsid#
7 : </cfquery>
8 : <html>

 
Can someone give me some suggestions on how to correct my code
rudodooAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgrafxCommented:
In the hyperlink on the results page - you must not have mlsid as in:
a href="results.cfm?stuff=#stuff#&mlsid=#mlsid#
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rudodooAuthor Commented:
Already figured it out thanks anyway
0
JeffHowdenCommented:
Make sure to "param" url.mlsid to a default value in case it's not passed in the url.

<cfparam name="url.mlsid" default="0">

<cfquery name="details" datasource="#Request.dsn#">
  SELECT *
    FROM MLS LEFT OUTER JOIN TblPicPaths
        ON TblPicPaths.mlsid = mls.mlsid
  WHERE MLS.mlsid= #Val(url.mlsid)#
</cfquery>
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dgrafxCommented:
>>rudodoo
DON'T default it to zero or any other number.
This is not a situation for a default param.
This is a situation for if it is not defined - you need to send them "back" to define it.

Glad you have it figured out though
0
JeffHowdenCommented:
Actually, sending them back to define it is poor design and an incorrect to the requested action.  If your application is designed properly, they should never need to go back to define it unless they're either messing with the url or they've bookmarked a URL with an mlsid that no longer exists.  It'd be more appropriate to give the user a 404 if it's not defined or the value sent results in the query not returning a result.  So, paraming it to 0 and dealing with a query that doesn't return a resultset is easier than having to test if the variable is defined *and* testing for a recordcount separately.  What you're suggesting will require more logic branching to accomplish unless you insist on incorrectly redirecting the user.

Again, from years of experience, here's my suggested approach:

<cfparam name="url.mlsid" default="0">

<cfquery name="details" datasource="#Request.dsn#">
  SELECT *
    FROM MLS LEFT OUTER JOIN TblPicPaths
        ON TblPicPaths.mlsid = mls.mlsid
  WHERE MLS.mlsid= #Val(url.mlsid)#
</cfquery>

<cfif NOT details.recordcount>
  <cfheader statuscode="404" statustext="File Not Found">
<cfelse>
  <!--- output the query results --->
</cfif>
0
dgrafxCommented:
>>Jeff
You must know I did not mean to just send them back, even though I used "back" in my statement.
I meant along the lines of if Not isDefined("thevar")  then send them to an appropriate page, because yes, it usually means the url vars are being messed with or it is a bot etc.

In general, questions answered here do not provide the entire code or solution, but are "how to" tips to get the question asker going.
Then if questions are still asked, a person can post additional details.
Some of the question askers here are complete newbees (sp?) and some are advanced developers with an issue.
It's generally outside the scope of most questions to get into or even touch upon all the aspects of building a quality application.
The question asker either knows this "stuff" or not, and if not then they'll learn it someday or not, and will become a quality developer or not.
0
JeffHowdenCommented:
Well, we apparently have a difference of opinion on how to answer questions.  I prefer to give as much detail as possible and to give insight into quality application development as possible too.  I'd rather assume they didn't know the "stuff" as something I may add based on that assumption could be a new perspective even a seasoned developer may not have heard.
0
dgrafxCommented:
Fair enough Jeff!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.