Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More Add Photo woes..

Status
Not open for further replies.

kelani

MIS
Nov 29, 2000
44
0
0
US
I'm still having trouble with this code! Basically, I'm using CFIF statements to allow a user to upload a photo, and if a photo already exists for that user, delete the existing one and update the database with the new one. Depending on hiw I lay this code out, i get one of two errors.

1. Context validation error in tag CFIF

The tag is not correctly positioned relative to other tags in the template: tag CFIF must have some content. This means that there must be at least one tag, some text, or even just whitespace characters between the <CFIF> and </CFIF> markers

2. The new photo uploads, but the information is not updated, and the old photo is not deleted.

If this is confusing, show me a cfif-cfelse layout that should work, like this

cfif- parameterexists-save

cfif-prepic.recordcount=1
cffifelseif prepic.recordcount=1

</cfif>
<cfelse>
</cfif>

Here we go.


<cfif ParameterExists(Save)>

<cfquery name=&quot;prepic&quot; datasource=&quot;dbname&quot; dbtype=&quot;ODBC&quot; username=&quot;usname&quot; password=&quot;pswd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
select id, photo, cap from users WHERE ID='#form.id#'
</cfquery>

<cfif prepic.recordcount IS &quot;1&quot;>

<cffile action=&quot;DELETE&quot; file=&quot;/home/kelani/public_html/lobd9/photos/#photo#&quot;>

<cffile action=&quot;UPLOAD&quot; filefield=&quot;photo&quot; destination=&quot;/home/kelani/public_html/lobd9/photos/&quot; nameconflict=&quot;MAKEUNIQUE&quot; accept=&quot;image/jpeg,image/gif,image/pjpeg&quot; mode=&quot;644&quot;>

<CFIF FILE.FileWasSaved Is True>
<CFSET theRealFileName = FILE.ServerFile>

<cfquery name=&quot;db_insert&quot; datasource=&quot;dbname&quot; dbtype=&quot;ODBC&quot; username=&quot;usname&quot; password=&quot;pswd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
UPDATE users SET photo='#theRealFileName#', cap='#cap#' WHERE ID='#form.id#'
</cfquery>
<cfoutput query=&quot;db_find&quot;><a href=&quot; Added!</a> View it now!
</center>
</cfoutput>

<cfelse>

<cffile action=&quot;UPLOAD&quot; filefield=&quot;photo&quot; destination=&quot;/home/kelani/public_html/lobd9/photos/&quot; nameconflict=&quot;MAKEUNIQUE&quot; accept=&quot;image/jpeg,image/gif,image/pjpeg&quot; mode=&quot;644&quot;>

<CFIF FILE.FileWasSaved Is True>
<CFSET theRealFileName = FILE.ServerFile>

<cfquery name=&quot;db_insert&quot; datasource=&quot;dbname&quot; dbtype=&quot;ODBC&quot; username=&quot;usname&quot; password=&quot;pswd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
UPDATE users SET photo='#theRealFileName#', cap='#cap#' WHERE ID='#form.id#'
</cfquery>
<cfoutput query=&quot;db_find&quot;><a href=&quot; Added!</a> View it now!
</cfoutput>
</center>

</cfif>

<cfelse>

(standard page shown if no parameters defined)



Thanks, you guys rule!

Kelani
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top