Skip to main content
Known Participant
July 19, 2011
Question

Variable PAGE_ID is undefined?

  • July 19, 2011
  • 1 reply
  • 1326 views

Hello,

I am new to ColdFusion and am having trouble with some code. I keep getting an error that the variable page_id is undefined. I do not have a form input for this code, I am just trying to get an output of something like this. Thanks in advance, any help is greatly appreciated!!

http://url/getImage.cfm?corner=558349

Here is my code.

<CFQUERY name="cr" datasource="sire" dbtype="odbc">


SELECT page_id
FROM  sire.dbo.CORNER_REPORTS_Page
WHERE page_id = <cfqueryPARAM value = "#page_id#"
CFSQLType = 'CF_SQL_INTEGER'>

</cfquery>

<cfset page_id = #page_id#>
<cfdump var = #page_id#>
<cfoutput>
<cfcontent file= "http://url/image/CORNER_REPORTS/0/#page_id#" type="application/pdf">
</cfoutput>

    This topic has been closed for replies.

    1 reply

    Owainnorth
    Inspiring
    July 19, 2011

    <CFQUERY name="cr" datasource="sire" dbtype="odbc">

      SELECT page_id
      FROM  sire.dbo.CORNER_REPORTS_Page
      WHERE page_id = <cfqueryPARAM value = "#page_id#"     <!--- Here you're referencing #page_id#, which hasn't been set anywhere
                                          CFSQLType = 'CF_SQL_INTEGER'>

    </cfquery>

    In the query, you're referencing a variable called page_id, but you haven't set that anywhere. Did you mean to use #url.corner#? You have a URL variable in there which looks suspiciously like it's there for a reason

    There's then no reason to set the result to anything afterwards, you can just reference the variable using queryname.columnname (assuming it only returns one row) - ie:

    <cfoutput>#cr.page_id</cfoutput>

    Hope that halps a little.

    Known Participant
    July 19, 2011

    Thanks for your help.

    The URL is in there just as a holding spot for the ip address I am accessing. I guess I do not understand what you mean by setting #url.corner#. Do you mind elaborating?

    Owainnorth
    Inspiring
    July 19, 2011

    Okay, if the URL is not important then forget all about it.

    Where has this page_id come from? Basically your page is starting by doing a query, saying "get me everything for the page Id I'm about to give you" - but there *is* no page_id, as it hasn't been set anywhere - hence your error message.

    What is going to set that Id? Is it coming from a form? Or a link somewhere?