Skip navigation
Currently Being Moderated

Element is undefined in url

May 8, 2012 7:04 AM

Hi all

The cfif doesn't appear to be working, if I add sectorid=1 to the url it works but throws an error if there is no value. Why is this not working? Thank you

 

<cfquery name="qNames" datasource="sales">

    select * from COMPANY, sector

where COMPANY.sectorid = sector.sectorid

<cFIF IsDefined(url.sectorID)>

and sector.sectorid = #url.sectorid#

</cfif>

</cfquery>

 
Replies
  • Currently Being Moderated
    May 8, 2012 7:12 AM   in reply to goodychurro1

     

     

    Lyndon Patton

    405-301-0952

    www.ohrc.org

    iPhone

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 7:15 AM   in reply to goodychurro1

    You're not using isDefined() properly.

     

    Read the docs:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461 172e0811cbec22c24-7fbd.html

     

    And pay close attention to the example code.

     

    Also: you're better off using structKeyExists() than isDefined(): isDefined() is flaky sometimes, and is kind of a hangover from older versions of CF.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 7:20 AM   in reply to goodychurro1

    <cFIF IsDefined("url.sectorID")>

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 8:32 AM   in reply to goodychurro1

    but the page throws an error if there is page.cfm without any sectorid parameter

     

     

    If you ever get an error you want help with, don't just tell us you got an error, tell us what the error is.  Inded paying close attention to the error message will generally tell you where you're going wrong.

     

    Also, look at this:

     

     

    <cfquery name="sNames" datasource="sales">
        select * from COMPANY, sector
    where <cFIF IsDefined('url.sectorID')>
    sector.sectorid = #url.sectorid#
    </cfif>
    </cfquery>

     

     

    If there is no sectorid, what SQL will that create?

     

    The SQL being sent to the DB should be part of the error message, btw...

     

    --
    Adam

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points