Solved

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

Posted on 2014-02-20
7
438 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
  • 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 52

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
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!

 
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 52

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP - problem with MS SQL Select Query? 10 61
IIS components 2 30
SQL to JSON 14 30
SQL Query Returns Records in SSMS but not Classic ASP 5 18
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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