I have a coldfusion script that initially uploads images to a folder structure and a database. Then I have these images display on a page via a cfloop query which gathers them and lays them out nice and neat. I also have a form that is generated for each image which gives the end user the option of deleting the image, rotating the image, resizing the image, or adding a caption.
All is well, except the add caption part. Check out the code...
This is the display page generated via cfloop query. It lays out all the images with a mini-form below each one with all the editing options.
<cfloop query="getdetails" startrow="#startrecord#" endrow="#Displaynext#">
<cfif tc eq 0><!---If table columns = 0 --->
<tr bordercolor="000"></cfif>
<td align="center" valign="middle" <cfif #columndisplay# is 3 > width="33%"<cfelse>width="25%"</cfif>>
<div id="style"><form method="post" name="deleteSelected" action="delete_images.cfm" enctype="multipart/form-data">
<cfoutput><font face="Arial, Helvetica, sans-serif" size="2">
<a href="java script:PopupPic('imgid=#getdetails.imgID#')"><img src="#dir##getdetails.thumb#" border=1
height=110 alt="Click for Fancy-Ass Big Shot!"></a>
</font>
<fieldset class="radio">
<label for="ninety">
<input type="checkbox" name="ninety" value="#imgid#">90
</label>
<label for="oneeighty">
<input type="checkbox" name="oneeighty" value="#imgid#">180
</label>
<label for="delete">
<input type="checkbox" name="delete" value="#imgid#">Delete
</label>
<label for="caption">
<input type="text" name="caption" value="" size=19>Add Caption
<INPUT TYPE="hidden" NAME="imgid" VALUE="#imgid#">
</label>
</fieldset>
</div>
</cfoutput>
<cfset tc=#tc#+1>
</td>
<cfif tc eq #columndisplay#>
</tr>
<cfset tc=0>
</cfif>
</cfloop>
<a href="../FlexFileUpload.html" target="_self">Return to Upload Module</a></br>
<a href="../flash_gallery/ncdoc_photo.html" target="_self">View Image Gallery</a></p>
<input name="Submit" type="submit" value="Modify Selected Data" class="submit"></br>
</form>
Here is the action page, trimmed to just show the activity on the add caption portion of the form...
<cfif isDefined("form.caption")>
<cfloop list="#form.caption#" index="i">
<cfquery name="InsertCaption" datasource="#datasource#">
UPDATE gallery
SET caption='#i#'
WHERE imgID = #imgid#
</cfquery>
</cfloop>
</cfif>
So this says to me, loop through all the images to find out which ones have information in their input=text field, get the values and assign them to index=i.
Then access the database, and update the gallery table with the caption data, but only on the records that have an imgID equal to the imgid of the images adding caption. #imgid# is established in the form via a hidden field which gets it's value from a prior cfquery.
This works great when there is only one image. when I add another image, I get the following error...
Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (comma) in query expression 'imgID = 218,219'. The error occurred in C:\ColdFusion8\wwwroot\local\multiGallery\gallery\delete_images.cfm: line 110 108 : UPDATE gallery 109 : SET caption='#i#' 110 : WHERE imgID = #imgid# 111 : </cfquery> 112 : -------------------------------------------------------------------------------- SQLSTATE 42000 SQL UPDATE gallery SET caption='asdf' WHERE imgID = 218,219 VENDORERRORCODE -3100 DATASOURCE multiGallery
I can see very clearly what's going on here. The form is passing the caption value of only the first image, but both the imgid's of the images, resulting in an #imgid# = 216, 218.
This makes sense, but I don't know how to get the information to be treated separately. I suspect it may be an additional loop of some kind? I'm playing around with it, but any tips would be greatly appreciated. Thanks!

New Topic/Question
Reply




MultiQuote





|