ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old February 19th, 2004, 05:45 PM
carment carment is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 21 carment User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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!!!

Reply With Quote
  #2  
Old February 19th, 2004, 06:05 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,480 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 33 m 17 sec
Reputation Power: 42
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.

Reply With Quote
  #3  
Old February 23rd, 2004, 12:45 PM
carment carment is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 21 carment User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you so much for your reply. You were right. All I needed to do was pass those variables in the URL.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > passing variables between multiple pages


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway