#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    21
    Rep Power
    0

    Question passing variables between multiple pages


    Hi!
    I am a new Cold Fusion user and I am currently developing a graphics library. Right now, my application enables users to perform a search (this happens on a search_images.cfm page, in which I use two variables: "keyword" for the input box and "display" because users have the option to display 8, 18, or 32 graphics at a time); once the query is displayed (search_results.cfm), if the records are more than 4, 8, or 16, then they can click on a Next link to view additional records. Also, they can click on each thumbnail to view the enlarged version of that graphic. My problem occurs when they click each graphic to view its enlarged version, because the link points them to yet anohter page (open_pictures_search.cfm), in which the "keyword" and "display" variables are not defined... I am attaching my code for these three pages. Please help.

    search_images.cfm
    <table id="data"><tr><td class="smallfieldcell">
    Type a keyword to start your search.<br>
    <form action="search_results.cfm" method="get">
    <input type="text" name="keyword" size=40>
    Show <select name="display">
    <option>4
    <option>8
    <option>16
    </select>
    graphics per page.<p>
    <input type="submit" value="Search">
    </form>
    </td></tr>
    </table>

    search_results.cfm
    <cfset DSN="etc">
    <cfquery datasource='#DSN#' name='GetRecords'>
    select *
    from media
    Where description like '%#keyword#%'
    </cfquery>
    <cfparam name="start" default="1">
    <cfset nextX = #start# + #display#>
    <cfset PrevX = #start# - #display#>
    <cfif PrevX LTE 0>
    <cfset PrevX = 1>
    </cfif>

    <h3>Search results</h3>

    <cfif GetRecords.recordcount is "0">
    No records match your search criteria. <br>
    Please click the Search link and try again.
    <cfelse>
    <p>You have searched for: <strong><cfoutput>#keyword#</cfoutput></strong><br>
    Your search returned <strong><cfoutput>#GetRecords.recordcount#</cfoutput></strong> results. Here they are:
    <p><table border=1>
    <tr>
    <cfoutput query="GetRecords" startrow="#start#" maxrows="#display#">
    <td width="25%" valign="top">
    <table><tr><td>#GetRecords.caption#</td></tr><tr><td><a href="javascript:launch_picture();"><img src="images/#filename#" width="100" border="0"></a></td></tr></table>
    </td>
    <cfif GetRecords.CurrentRow MOD 4 IS 0>
    </tr>
    </cfif>
    </cfoutput>
    </table>

    <p>
    <cfif #start# is not 1>
    <cfoutput>
    <a href="search_results.cfm?start=#PrevX#&display=#display#&keyword=#keyword#">
    previous
    </a>
    </cfoutput>
    </cfif>
    &nbsp;
    <!---Next (X) (only show this link if there are more results available)--->
    <cfif nextX LTE GetRecords.RecordCount>
    <cfoutput>
    <a href="search_results.cfm?start=#nextX#&display=#display#&keyword=#keyword#">
    next
    </a>
    </cfoutput>
    </cfif>
    </cfif>

    open_pictures_search.cfm
    <cfquery name="viewpictures" datasource="#dsn#">
    select * from media
    where pictureid = #cid#
    </cfquery>

    <cfoutput query="viewpictures">
    <cfform action="" method="">
    <input type="hidden" name="pictureid" value="#pictureid#">
    <TABLE align="center" class="data">
    <TD align="left" valign="top" class="picturecell">
    <IMG SRC="admin/images/#filename#" align="top"></TD></tr>
    <tr><td align="center">#viewpictures.caption#</td></tr>
    <tr><td align="center"><a href="search_results.cfm?cid="#pictureid#">Back to search results</a></td></tr>
    </table>
    </cfform>
    </cfoutput>

    Thank you!!!
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    A few things:

    First, you only need pound signs when you are outputting a variable or if you are evaluating a dynamic expression. So instead of:

    <cfset nextX = #start# + #display#>

    Just do:

    <cfset nextX = start + display>

    Second, this is wide open to a possible SQL injection attack if someone clever passes additional SQL statements within the variable cid (note that this applies to ANY scripting language, not just ColdFusion):

    <cfquery name="viewpictures" datasource="#dsn#">
    select * from media
    where pictureid = #cid#
    </cfquery>

    Use <cfqueryparam>, or at least use #val(cid)# to eliminate the chance that a user can append additional SQL data to #cid#. Also you really should be scoping #cid#. Is this a form variable, a url variable, a local variable? Use something like #url.cid#.

    Now to your actual problem, I'm actually not sure quite what it is. If it is that when a user opens a picture and then clicks the "return to search results" link, there is no "display" or "keyword" variable in the link back? Can you not just pass these in the URL? Or is the problem that on the "open_picture_search.cfm" page that "display" and "keyword" aren't passed into it? Same story, why not just pass it in the link to that page? If neither of these are applicable please explain the problem a bit further.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    21
    Rep Power
    0
    Thank you so much for your reply. You were right. All I needed to do was pass those variables in the URL.

IMN logo majestic logo threadwatch logo seochat tools logo