Solved

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

Posted on 2014-02-20
7
419 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 32

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now