dame.cranon wrote:
> Hello all. I'm having a little issue with a multiple
upload I am trying to
> achieve. I've been searching and searching but could not
find an answer, and
> maybe you guys could help me. Well I'm doing multiple
uploads on a form i
> created and it's uploading the file and file name
correctly, but it's inserting
> 6 records everytime I'm hitting the submit button. Also,
I've notice in my
> database is when you click the submit button, it's
inserting the same file in
> one record 6 times, then it creates a new record and
inserts the second file 6
> times. I'm going to post the code here, maybe it's
something I'm missing, not
> sure. Thanks for the help.
>
>
>
> <cfloop index="i" from="1" to="6">
>
> <cfif isDefined("form.upload")>
>
> <cffile action="upload"
> destination="D:\Hosting\streetzmag\dev\crush_images\"
> filefield="pic#i#"
> nameconflict="makeunique"
> result="cffile.pic#i#"
> accept="image/jpeg, image/pjpeg, image/gif" >
>
> <!--- Code for insert of information --->
> <cfquery datasource="mysqlcf_streetzmag"
name="uploaded">
> INSERT INTO Information(firstname,
> lastname,
> email,
> contact_info,
> nickname,
> recent_work,
> hair_color,
> eye_color,
> ethnicity,
> age,
> height,
> measurements,
> pic_1,
> pic_2,
> pic_3,
> pic_4,
> pic_5,
> pic_6
>
>
> )
> VALUES('#FORM.firstname#',
> '#FORM.lastname#',
> '#FORM.email#',
> '#FORM.contact#',
> '#FORM.nickname#',
> '#FORM.work#',
> '#FORM.hair#',
> '#FORM.eye#',
> '#FORM.ethnic#',
> #FORM.age#,
> '#FORM.height#',
> '#FORM.measurements#',
> <cfif isDefined("form.pic#i#") and
evaluate("form.pic#i#") NEQ "">
> <cfqueryparam
value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
> />
> <cfelse>
> NULL
> </cfif>,
>
> <cfif isDefined("form.pic#i#") and
evaluate("form.pic#i#") NEQ "">
> <cfqueryparam
value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
> />
> <cfelse>
> NULL
> </cfif>,
>
> <cfif isDefined("form.pic#i#") and
evaluate("form.pic#i#") NEQ "">
> <cfqueryparam
value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
> />
> <cfelse>
> NULL
> </cfif>,
>
> <cfif isDefined("form.pic#i#") and
evaluate("form.pic#i#") NEQ "">
> <cfqueryparam
value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
> />
> <cfelse>
> NULL
> </cfif>,
>
> <cfif isDefined("form.pic#i#") and
evaluate("form.pic#i#") NEQ "">
> <cfqueryparam
value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
> />
> <cfelse>
> NULL
> </cfif>,
>
> <cfif isDefined("form.pic#i#") and
evaluate("form.pic#i#") NEQ "">
> <cfqueryparam
value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
> />
> <cfelse>
> NULL
> </cfif>
>
> )
> </cfquery>
> </cfif>
> </cfloop>
>
of course it will do everything 6 times since you have your
whole code
wrapped with cfloop from 1 to 6... so the code execution will
happen 6
times... plus your synatx for inserting filenames inside your
query
makes it insert same file 6 times (since the code is inside
one same
cfloop)...
you should separate your code and wrap only the cffile part
in a cfloop:
<cfif isDefined("form.upload")>
<cfloop index="i" from="1" to="6">
<cfif len(trim(form.pic#i#)) gt 0>
<cffile action="upload"
destination="D:\Hosting\streetzmag\dev\crush_images\"
filefield="pic#i#"
nameconflict="makeunique"
result="uploadedpic_#i#"
accept="image/jpeg, image/pjpeg, image/gif" >
</cfif>
</cfloop>
<!--- Code for insert of information --->
<cfquery datasource="mysqlcf_streetzmag"
name="uploaded">
INSERT INTO Information
(firstname,
lastname,
email,
contact_info,
nickname,
recent_work,
hair_color,
eye_color,
ethnicity,
age,
height,
measurements,
pic_1,
pic_2,
pic_3,
pic_4,
pic_5,
pic_6)
VALUES('#FORM.firstname#',
'#FORM.lastname#',
'#FORM.email#',
'#FORM.contact#',
'#FORM.nickname#',
'#FORM.work#',
'#FORM.hair#',
'#FORM.eye#',
'#FORM.ethnic#',
#FORM.age#,
'#FORM.height#',
'#FORM.measurements#',
<cfloop from="1" to="6" index="x">
<cfif isdefined("uploadedpic_#x#")>
<cfqueryparam value="#evaluate('uploadedpic_' & x)#"
cfsqltype="cf_sql_varchar"/>
<cfelse>
NULL
</cfif>
<cfif x lt 6>,</cfif>
</cfloop>)
</cfquery>
</cfif>
--
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com