Dynamically add posted form items into array

D

Daniel Gormley

What I have is a form that is dynamically generated based on which
database table its calling. Therefore, the number of category.name.count
can be different.

So I have this form generated and say with x amount of input boxes.. I
enter data in the boxes and submit.

The data submitted is needing to be placed into an array for insert into
a database.

The code I have so far is this:

<%
Response.Write ("Form Data: " & Request.Form & "<br/>")

If Request.Form("updateTable") <> "" then
For Each Item In Request.Form
x = Item
y = Request.Form(Item)
Response.Write "Item: " & X & " - " & Y & "<br/>"
Next

'###############################
'##### Unfinised SQL Query #####
SQL = "INSERT INTO '" & updateTable & "' SET "
'###############################

End If

if Request.Form("table") = "" then

Else
Response.Write "<br/><br/>"
tablename = Request.Form("table")

Call OpenDB()

SQL = "SELECT * FROM tbl" & tablename
Set RS = CN.Execute(SQL)
Response.Write "<form method=""post"" action=""index.asp"">"
Response.Write "<input type=""submit"" value=""Submit"" name=""B1"">" &
vbCrLf
Response.Write "<input type=""hidden"" name=""updateTable"" value=""tbl"
& tablename & """ />" & vbCrLf
Response.Write "<table border=""1"" cellpadding=""5"">" & vbCrLf
Response.Write "<tr>" & vbCrLf

for each Category in RS.fields
Response.Write "<td><b>" & Category.name & "</b></td>" & vbCrLf
next

col = Rs.Fields.Count

Response.Write "</tr>" & vbCrLf
Response.Write "<tr>" & vbCrLf

for each Category in RS.fields
Response.Write "<td><input type=""text"" name=""" & Category.name & """
size=""20"" /></td>" & vbCrLf
next
Response.Write "</tr>" & vbCrLf

If RS.EOF Then
Response.Write "<tr>" & vbCrLf
Response.Write "<td colspan=""" & col & """ align=""center"">" & vbCrLf
Response.Write "No records matched!<br/> Number of Fields: " & col
Response.Write "</td>" & vbCrLf
Response.Write "</tr>" & vbCrLf
Response.Write "</table>" & vbCrLf
Response.Write "</form>"
Else
alldata = RS.GetRows
End If
Call CloseDB()
%>

Im kinda lost as to how to get the form data into an array where I can
do my SQL query...
 
S

Steven Burn

If Request.Form("updateTable") <> "" then
For Each Item In Request.Form
x = Item
y = Request.Form(Item)
If Len(arrItems) > 0 Then
arrItems = arrItems & ",," & X & " - " & Y '// Seperate with
double comma
Else
arrItems = X & " - " & Y '// Seperate with double comma
End If
Next

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top