Skip to main content
Known Participant
March 8, 2012
Question

CFC URL variable

  • March 8, 2012
  • 1 reply
  • 1675 views

I am having trouble with a URL varailble.  Does anyone know how to send a URL variable to the query in a CFC.  Here is what I have so far and it does not work. Thanks.

CFC:

<cffunction name="pagevideo" access="public" returntype="query">

  <cfset var pagevideo="">

  <cfif not IsDefined("URL.VideoID")>

    <cflocation url="page.cfm?videoID=486">

  <cfelse>

    <cfquery name="pagevideo" datasource="videos">

          SELECT video_path, ID, Video_Name,

    FROM Video

    WHERE ID = #URL.VideoID#

          </cfquery>

  </cfif>

  <cfreturn aged240video>

</cffunction>

CFM page:

<cfset myObj = createObject("component","cfc.page") />

<cfset queryObj = myObj.pagevideo()>

  <h2 >Page Header</h2>

<cfoutput><h2 >#queryObj.Video_Name#</h2></cfoutput>

    This topic has been closed for replies.

    1 reply

    Inspiring
    March 8, 2012

    What is the error message, if any, you receive.  I also that the variable aged240video in your cfreturn is not defined. 

    Try <cfreturn pagevideo> instead. 

    You should also omit the line <cfset var pagevideo="">.

    You should also use CFQUERYPARAM in your query when passing in URL.VideoID.

    Known Participant
    March 8, 2012

    I already changed it to pagevideo.  The error I get is as follows

    Error Executing Database Query.

    [Macromedia][SequeLink JDBC Driver][ODBC Socket][FileMaker][FileMaker] FQL0001/(1:36): There is an error in the syntax of the query.


    How would I use CFQUERYPARAM?

    Inspiring
    March 8, 2012

    It appears that you have an extra comma after Video_Name in your query.  I suspect that this is causing the error.

    The CFQUERYPARAM tag is used to bind parameters to your SQL statements.  Use of bound parameters is recommended to avoid SQL injection attack vulnerability.

    See:

    Assuming that the ID column is an integer:

    <cfquery name="pagevideo" datasource="videos">

        SELECT video_path, ID, Video_Name

        FROM Video

        WHERE ID = <cfqueryparam value="#URL.VideoID#" cfsqltype="cf_sql_integer">

    </cfquery>

    References:

    CFQUERYPARAM

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f6f.html

    SQL Injection (Wikipedia)

    http://en.wikipedia.org/wiki/Sql_injection