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="prepic" datasource="dbname" dbtype="ODBC" username="usname" password="pswd" dbserver="localhost" dbname="dbname">
select id, photo, cap from users WHERE ID='#form.id#'
</cfquery>
<cfif prepic.recordcount IS "1">
<cffile action="DELETE" file="/home/kelani/public_html/lobd9/photos/#photo#">
<cffile action="UPLOAD" filefield="photo" destination="/home/kelani/public_html/lobd9/photos/" nameconflict="MAKEUNIQUE" accept="image/jpeg,image/gif,image/pjpeg" mode="644">
<CFIF FILE.FileWasSaved Is True>
<CFSET theRealFileName = FILE.ServerFile>
<cfquery name="db_insert" datasource="dbname" dbtype="ODBC" username="usname" password="pswd" dbserver="localhost" dbname="dbname">
UPDATE users SET photo='#theRealFileName#', cap='#cap#' WHERE ID='#form.id#'
</cfquery>
<cfoutput query="db_find"><a href=" Added!</a> View it now!
</center>
</cfoutput>
<cfelse>
<cffile action="UPLOAD" filefield="photo" destination="/home/kelani/public_html/lobd9/photos/" nameconflict="MAKEUNIQUE" accept="image/jpeg,image/gif,image/pjpeg" mode="644">
<CFIF FILE.FileWasSaved Is True>
<CFSET theRealFileName = FILE.ServerFile>
<cfquery name="db_insert" datasource="dbname" dbtype="ODBC" username="usname" password="pswd" dbserver="localhost" dbname="dbname">
UPDATE users SET photo='#theRealFileName#', cap='#cap#' WHERE ID='#form.id#'
</cfquery>
<cfoutput query="db_find"><a href=" Added!</a> View it now!
</cfoutput>
</center>
</cfif>
<cfelse>
(standard page shown if no parameters defined)
Thanks, you guys rule!
Kelani
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="prepic" datasource="dbname" dbtype="ODBC" username="usname" password="pswd" dbserver="localhost" dbname="dbname">
select id, photo, cap from users WHERE ID='#form.id#'
</cfquery>
<cfif prepic.recordcount IS "1">
<cffile action="DELETE" file="/home/kelani/public_html/lobd9/photos/#photo#">
<cffile action="UPLOAD" filefield="photo" destination="/home/kelani/public_html/lobd9/photos/" nameconflict="MAKEUNIQUE" accept="image/jpeg,image/gif,image/pjpeg" mode="644">
<CFIF FILE.FileWasSaved Is True>
<CFSET theRealFileName = FILE.ServerFile>
<cfquery name="db_insert" datasource="dbname" dbtype="ODBC" username="usname" password="pswd" dbserver="localhost" dbname="dbname">
UPDATE users SET photo='#theRealFileName#', cap='#cap#' WHERE ID='#form.id#'
</cfquery>
<cfoutput query="db_find"><a href=" Added!</a> View it now!
</center>
</cfoutput>
<cfelse>
<cffile action="UPLOAD" filefield="photo" destination="/home/kelani/public_html/lobd9/photos/" nameconflict="MAKEUNIQUE" accept="image/jpeg,image/gif,image/pjpeg" mode="644">
<CFIF FILE.FileWasSaved Is True>
<CFSET theRealFileName = FILE.ServerFile>
<cfquery name="db_insert" datasource="dbname" dbtype="ODBC" username="usname" password="pswd" dbserver="localhost" dbname="dbname">
UPDATE users SET photo='#theRealFileName#', cap='#cap#' WHERE ID='#form.id#'
</cfquery>
<cfoutput query="db_find"><a href=" Added!</a> View it now!
</cfoutput>
</center>
</cfif>
<cfelse>
(standard page shown if no parameters defined)
Thanks, you guys rule!
Kelani