Store all non file posted input values from a form to my database with a loop

Hi Experts,

I've got 20 documents with over 114 concurrent questions about 36 each. So I've put them in a table in my database and I've made ajax drag and drop interface so document management is easy.

The input part is ready but now I have to complete the part that saves all fields into the database.

I've got a excellent working script called "FreeASPUpload" that stores my files but now I'd like to store all my other on file input fields into my database.

Could I, like the script does in loop from line 18 to 25, save all other input to my database?
The value names from the <input fields correspond with the database fieldnames!

Line 29 to 32 show the working syntax for non file fields

If this is possible can someone give a hint or example how to do this?

<%@ Language=VBScript %>
<% 
'option explicit 

Response.Expires = -1
Server.ScriptTimeout = 600
Session.CodePage  = 65001
%>
<!-- #INCLUDE FILE="config.asp"-->
<!-- #INCLUDE FILE="freeaspupload.asp" -->
<%
Dim uploadsDirVar, Upload, fileName, ks, fileKey, oldname, newname
uploadsDirVar = "C:\Inetpub\wwwroot\test\Uploads" 
Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> 0) then
    for each fileKey in Upload.UploadedFiles.keys
        oldname = Upload.UploadedFiles(fileKey).FileName
		DateTime = DateAdd("h", 3, Time)
		newname = DateTime & oldname
		dim fs
		set fs=Server.CreateObject("Scripting.FileSystemObject")
		fs.MoveFile oldname , newname
		set fs=nothing
    next
end if

'test output
Response.write Upload.Form("firstname") & "<br>"
Response.write Upload.Form("lastname") & "<br>"
%>

Open in new window

LVL 1
SteynskAsked:
Who is Participating?
 
Big MontyConnect With a Mentor Senior Web Developer / CEO of ExchangeTree.org Commented:
just kind of thinking out loud here (in my head) and you should be able to for a for next statement using the Upload.Form collection:

 '-- add your form elements here that you do not want saved, such as buttons, hidden vars if you don't want them saved, and the file fields. if you have a common string of chars for your file fields (such as "flUpload1, flUpload2", just add the prefix here
strExceptions = "btnSave, btnCancel, etc"    
for each fldName in Upload.Form
    if InStr( fldName, strExceptions ) = 0 then      '-- check field name against list of exceptions
         listOfColumns = listOfColumns & fldName & "," )
         if isNumeric( Upload( fldName ) then
             listOfValues = listOfValues & Upload( fldName ) & ","
          else
             listOfValues  = listOfValues & '" & Upload( fldName ) & "',"
          end if
    end if
next

'-- strip off final commas
if Right( listOfColumns, 1 ) = "," then listOfcolumns = Left( listOfColumns, Len( listOfColumns ) - 1 )
if Right( listOfValues, 1 ) = "," then listOfValues = Left( listOfValues, Len( listOfValues ) - 1 )

sql = "insert into tblName ( " & listOfColumns & " ) values ( " & listOfValues & " )"
conn.Execute( sql )

Open in new window


keep in mind that this is just an example of how you could possibly tackle this situation. I only know very basic things about the project so I couldn't tailor it to what you need exactly, but you should be able to see what I was doing and get it working with your code.
0
 
Scott Fell, EE MVEDeveloperCommented:
I have dropzone on my docket to implement over the next couple of days.  http://www.dropzonejs.com/  You can add multiple files and the js takes care of the front and and you would still use your aspupload to accept the file just as if a form is used as in your current script.  Make sure to make the folder you are uploading to able to write.   I am going to follow the instructions for php.  As soon as I get to it, I will report back here but it seems simple enough.
0
 
SteynskAuthor Commented:
Hi Big Monty,

Thanks for your quick response. Like you said it is an example and I did try it but until now without success.

I'm getting this error:

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Form'

/entree/formulier_post.asp, line 32

This my best effort:

 
<%@ Language=VBScript %>
<% 
'option explicit 

'Response.Expires = -1
Server.ScriptTimeout = 600
Session.CodePage  = 65001
%>
<!-- #INCLUDE FILE="config.asp"-->
<!-- #INCLUDE FILE="freeaspupload.asp" -->
<%
Dim uploadsDirVar, Upload, fileName, ks, fileKey, oldname, newname
uploadsDirVar = "C:\Inetpub\wwwroot\test\Uploads" 
Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> 0) then
    for each fileKey in Upload.UploadedFiles.keys
        oldname = Upload.UploadedFiles(fileKey).FileName
		DateTime = DateAdd("h", 3, Time)
		newname = DateTime & oldname
		dim fs
		set fs=Server.CreateObject("Scripting.FileSystemObject")
		fs.MoveFile oldname , newname
		set fs=nothing
    next
end if

dim listOfColumns, listOfValues
 '-- add your form elements here that you do not want saved, such as buttons, hidden vars if you don't want them saved, and the file fields. if you have a common string of chars for your file fields (such as "flUpload1, flUpload2", just add the prefix here
strExceptions = "subbut"    
for each fldName in Upload.Form
    if InStr( fldName, strExceptions ) = 0 then      '-- check field name against list of exceptions
         listOfColumns = listOfColumns & fldName & "," 
         if isNumeric( Upload( fldName ) )then
             listOfValues = listOfValues & Upload( fldName ) & ","
          else
             listOfValues  = listOfValues & "'" & Upload( fldName ) & "',"
          end if
    end if
next
response.write listOfColumns & "<br>"
response.write listOfValues & "<br>"
response.end
'-- strip off final commas
if Right( listOfColumns, 1 ) = "," then listOfcolumns = Left( listOfColumns, Len( listOfColumns ) - 1 )
if Right( listOfValues, 1 ) = "," then listOfValues = Left( listOfValues, Len( listOfValues ) - 1 )

sql = "insert into entree_fase1 ( " & listOfColumns & " ) values ( " & listOfValues & " )"
cs.Execute( sql )

%>

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
SteynskAuthor Commented:
Thanks Padas,

I'm very interested to hear your results. Ans yes the upload folder has write access and it works I only need to catch the non file input.  I'm looking for a way like in the script above (lines 32 to 41). That dynamically builds the insert query. I know how to make a simple insert query but how do I catch all non file input the form sends to the server based process script?

best regards,

Steynsk
0
 
Scott Fell, EE MVEDeveloperCommented:
It's going to be a day or 3 until I can get to that.  It looks simple enough where you can just plug in your upload script and accept form input generated by dropping files. That script would be in place of the traditional form input.
0
 
SteynskAuthor Commented:
I found the solution to my question:


Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)
for each objItem in Upload.FormElements
    response.write(objItem & ": " & Upload.Form(objItem) & "<br>") 
next

Open in new window


The save must take place before you will get results.
0
 
SteynskAuthor Commented:
Thanks you helped my in the right direction
0
All Courses

From novice to tech pro — start learning today.