Solved

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

Posted on 2014-02-20
7
441 Views
Last Modified: 2014-02-21
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

0
Comment
Question by:Steynsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39873945
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
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39874954
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
 
LVL 1

Author Comment

by:Steynsk
ID: 39876160
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Steynsk
ID: 39876166
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
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39876275
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
 
LVL 1

Author Comment

by:Steynsk
ID: 39876450
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
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 39876451
Thanks you helped my in the right direction
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Html form and modal / img src -problem 3 61
Read text on Table 7 50
JS to redirect to prev page 8 47
Compress Newid value ms sql Mssql 4 48
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question