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!

Adding multiple records. 3

Status
Not open for further replies.

theogary

Programmer
Mar 3, 2003
99
0
0
US
Instead of adding 1 record at time, the user wants to add 5,10, or 15 records on one screen.

How can this be done
 
The amount of information regarding a "record" is minimal in your post.

Add 'x' amount of inputs, say 15. Then loop thru the results adding an insert query in the loop.

One field would be like:
<cfloop list=&quot;form.textfield&quot; index=&quot;Idx&quot;>
<cfquery name=&quot;etc&quot; datasource=&quot;etcetc&quot;>
insert stuff
</cfquery>
</cfloop>


DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
I wrote a page to allow for multipe uploads. same theory as what you're looking for hope it helps.

Note: I'm in a hurry to leave and I had to change this a little I think I got it all so it would work
Code:
<!--- set default uploads --->
<cfparam name = &quot;session.maxUpLoad&quot; default = &quot;5&quot;>
<!--- Check for max upload change --->
<cfif isdefined(&quot;form.maxUpLoadChanged&quot;)>
	<!-- Check for valid input (A number and > 0) --->
	<cfif val(form.newMaxUpLoad) gt 0>
		<!--- set new max upload to user defined value --->	
		<cfset session.maxUpload = #val(form.newMaxUpLoad)#>
	<cfelse>
		<!--- Identify Invalid entery if input is not a number --->	
		<cfset invalidNumber = true> 
	</cfif>
</cfif>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
	<TITLE>Upload Form</TITLE>
	<META http-equiv=Content-Type content=&quot;text/html; charset=iso-8859-1&quot;>
	<META content=&quot;MSHTML 6.00.2800.1170&quot; name=GENERATOR>
</HEAD>
<BODY bgColor = &quot;#ffffff&quot;>
<TABLE borderColor = &quot;#000000&quot; cellSpacing = &quot;1&quot; cellPadding = &quot;3&quot; width = &quot;100%&quot; bgColor = &quot;#000000&quot; border = &quot;0&quot;>
	<TR>
		<TD vAlign = &quot;bottom&quot; noWrap align = &quot;right&quot; width = &quot;129&quot; bgColor = &quot;#000000&quot;><br></TD>
		
  <TD noWrap width = &quot;100%&quot; bgColor = &quot;#000000&quot;><FONT face = &quot;Tahoma, Arial, sans-serif&quot; color = &quot;#ffffff&quot; size = &quot;4&quot;><STRONG> Max Upload Form</STRONG></FONT></TD>
	</TR>
    <TR>
   <TD align=&quot;right&quot; vAlign=center noWrap bgColor=#333366>
      		<FONT color = &quot;#ffffff&quot; size = &quot;1&quot; face = &quot;Tahoma, Arial, sans-serif&quot;><STRONG>Number Of files</STRONG></FONT>
		</TD>
<!--- Begin max file number form --->		
	 	<form name = &quot;changeMaxUploadForm&quot; method = &quot;post&quot; action = &quot;UploadForm.cfm&quot;>
	<TD noWrap bgColor=#99ccff>
<!--- Begin invalid number error notification to user --->			
	 <cfif isdefined(&quot;invalidNumber&quot;)>
	  <font color=&quot;#FF0000&quot; size=&quot;2&quot; face=&quot;Tahoma, Arial, sans-serif&quot;>Invalid Number Entered<br></font>
	 </cfif>
<!--- End invalid number error notification to user --->	   
	  		<INPUT type = &quot;text&quot; size = &quot;2&quot; name = &quot;newMaxUpLoad&quot; value = &quot;<cfoutput>#session.maxUpLoad#</cfoutput>&quot;>
	   		<input type = &quot;submit&quot; name = &quot;submit&quot; value = &quot;Update&quot;>
			<!--- Identify's a number change after submit --->
	   		<input type = &quot;hidden&quot; name = &quot;maxUpLoadChanged&quot; value = &quot;y&quot;> 
	   		<FONT size=&quot;3&quot; face=&quot;Tahoma, Arial, sans-serif&quot;>Change and submit before browsing for files.</FONT></TD>
		</form>
<!--- End max file number form --->
	</TR>
</TABLE>
<BR>
<!--- Do not show any file upload options if entry is invalid --->
<cfif not isdefined(&quot;invalidNumber&quot;)>
<br>
<!--- upload form --->
<FORM name = &quot;UpLoad&quot; action = &quot;UploadAction.cfm&quot; method = &quot;post&quot; enctype = &quot;multipart/form-data&quot;. >
<!--- set form variable incase session times out --->
<input type = &quot;hidden&quot; name = &quot;maxUpload&quot; value = &quot;<cfoutput>#session.maxUpload#</cfoutput>&quot;>
  <TABLE borderColor = &quot;#000000&quot; cellSpacing = &quot;1&quot; cellPadding = &quot;3&quot; width = &quot;100%&quot; bgColor = &quot;#000000&quot; border = &quot;0&quot;>
	  <TR>
	<TD vAlign=bottom noWrap align=right width=129 bgColor=#000000><br></TD>
	<TD noWrap width=&quot;100%&quot; bgColor = &quot;#000000&quot;>
	  		<FONT face = &quot;Tahoma, Arial, sans-serif&quot; color = &quot;#ffffff&quot; size = &quot;4&quot;><STRONG> Upload Form</STRONG></FONT>
		</TD>
   </TR>
<!--- Create number of requested or default file download options --->	
   <cfloop from = &quot;1&quot; to = &quot;#session.maxUpLoad#&quot; index = &quot;upLoadNumber&quot;>
    <TR>
		
	 <TD align=&quot;right&quot; vAlign = &quot;center&quot; noWrap bgColor = &quot;#333366&quot;>
	 		<!--- Identify file download number to the right of file --->
      		<FONT color = &quot;#ffffff&quot; size = &quot;1&quot; face=&quot;Tahoma, Arial, sans-serif&quot;><STRONG>File Number <cfoutput>#upLoadNumber#</cfoutput></STRONG></FONT></TD>
	 <TD noWrap bgColor = &quot;#99ccff&quot;>
	 		<!--- Create file upload option with sequential numbers in loop --->
   			<input type = &quot;file&quot; name = &quot;upLoad<cfoutput>#upLoadNumber#</cfoutput>&quot; size = &quot;40&quot;>
   		</td>
	</TR>
   </cfloop>
  </TABLE>
  <DIV align=center>
   <TABLE cellSpacing=6 width=640 border=0>
    <TR>
     <TD>
      <TABLE cellSpacing=6 align=center border=0>
        
	   <TR>
          
		<TD>
            <DIV align=center>
		  
		  <INPUT type = &quot;submit&quot; value = &quot;Submit&quot; name = &quot;submit&quot;>
            </DIV></TD>
	   </TR>
	  </TABLE></TD>
	</TR>
   </TABLE>
  </DIV>
  <!--- End upload form --->
 </FORM>

</cfif>
</BODY></HTML>

ACTION PAGE

<cfset physicalPath = &quot;D:\[URL unfurl="true"]www\uploads&quot;>[/URL]
<cfloop from = &quot;1&quot; to = &quot;#form.maxUpload#&quot; index = &quot;i&quot;>
<cfif IsDefined(&quot;FORM.upLoad#i#&quot;) and evaluate(&quot;FORM.upLoad&quot;&i) neq &quot;&quot;>
<cffile	action = &quot;Upload&quot;
		filefield = &quot;form.upLoad#i#&quot;
		destination = &quot;#physicalPath#uploads\temp&quot;
		nameconflict = &quot;overwrite&quot; >
<cfset files = arraynew(1)>
<cfset Files[i] = #cffile.clientfile#>
<cfoutput>#files[i]# Uploaded</cfoutput><br>
</cfif>
</cfloop>

thereptilian120x120.gif
 
Bombboy - your code was very helpful for a problem I'm trying to resolve. However, I need to upload the "files" and store the unique names in a database. (I used "make unique" instead of "overwrite" for the nameconflict attribute).
Essentially - here is my query. I end up getting three copies of the last file uploaded listed in my database. I'm sure that it's due to the repeated '#File.ServerFile#' but I'm not sure how to hold on to the names of the files I'm uploading to insert them into the database.

Any suggestions?


<CFQUERY DATASOURCE="#xDB#" DBTYPE="ODBC">
INSERT INTO horseTable(horse_picture1, horse_picture2, horse_picture3)
VALUES '#File.ServerFile#', '#File.ServerFile#', '#File.ServerFile#
</CFQUERY>
 
Change

Code:
<cfset files = arraynew(1)>
<cfset Files[i] = #cffile.clientfile#>

to

Code:
<cfset files = arraynew(1)>
<cfset Files[i] = #cffile.clientfile#>
<cfset sFiles = ArrayNew(1)>
<cfset sFiles[i] = #cffile.serverfile#>

and then

Code:
<CFQUERY DATASOURCE="#xDB#" DBTYPE="ODBC">
INSERT INTO horseTable(horse_picture1, horse_picture2, horse_picture3)
VALUES  '#sFiles[1]#', '#sFiles[2]#', '#sFiles[3]#    
</CFQUERY>

The reason you were getting the same file name was because each loop overwrote the value of client.serverfile.. So you needed to set it before the loop round finished.

As for bombboy.. Cool script.. I learned something about cffile from it.. or a better way to handle it at least.. You won't mind if I borrow and adapt? :)

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks WebMigit
I tried your suggestions but the "insertion" bombed. I get the following rather useless, error message...

Element 1 is undefined in a Java object of type class coldfusion.runtime.Array referenced as

I include the insert for reference.,,
INSERT INTO horseTable
(horse_picture1, horse_picture2, horse_picture3)
VALUES ('#sFiles[1]#', '#sFiles[2]#', '#sFiles[3])
</CFQUERY>
 
Thanks for the tip! The missing "octothorp" was an oversight when I copied the query into this forum. It is there in the actual code.
Wish my dilema was that easy to fix!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top