Steynsk
asked on
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?
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>"
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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:
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
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 )
%>
ASKER
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
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
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.
ASKER
I found the solution to my question:
The save must take place before you will get results.
Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)
for each objItem in Upload.FormElements
response.write(objItem & ": " & Upload.Form(objItem) & "<br>")
next
The save must take place before you will get results.
ASKER
Thanks you helped my in the right direction