Request.form usage not clear

J

Jack

Hi,
I am trying to get a thorough understanding of a code where a addition or
deletion of records can be done from a list of records. For addition part of
the form, data is being obtained from set of input boxes.
The following is the code being used:

If Len(Request.Form("ID_0"))>0 Then
AuthorID=Request.Form("ID_0")
FName=Request.Form("fName_0")
LName=Request.Form("lName_0")

' SQL will break on names like O'Leary
' if single quotes are not doubled.
LName=Replace(LName,"'","''")

Phone=Request.Form("Phone_0")
Address=Request.Form("Address_0")
City=Request.Form("City_0")
State=Request.Form("State_0")

' Create the UPDATE SQL Statement
sql = " INSERT INTO Authors (au_id, au_fName, "
sql = sql & "au_lName, phone, address, city, state)"
sql = sql & " VALUES('" & AuthorID & "','" & FName
sql = sql & "','" & LName & "','" & Phone
sql = sql & "','" & Address & "','" & City
sql = sql & "','" & State & "')"

' Execute the INSERT SQL
cnnPubs.Execute sql
intCount=1
End if
I am not clear where the 0 suffix is coming from in the following:
AuthorID=Request.Form("ID_0")
FName=Request.Form("fName_0")

Thanks for any help.
 
E

Evertjan.

=?Utf-8?B?SmFjaw==?= wrote on 25 mrt 2005 in
microsoft.public.inetserver.asp.general:
Hi,
I am trying to get a thorough understanding of a code where a addition
or deletion of records can be done from a list of records. For
addition part of the form, data is being obtained from set of input
boxes. The following is the code being used:

If Len(Request.Form("ID_0"))>0 Then
AuthorID=Request.Form("ID_0")
FName=Request.Form("fName_0")
LName=Request.Form("lName_0")

' SQL will break on names like O'Leary
' if single quotes are not doubled.
LName=Replace(LName,"'","''")

Phone=Request.Form("Phone_0")
Address=Request.Form("Address_0")
City=Request.Form("City_0")
State=Request.Form("State_0")

' Create the UPDATE SQL Statement
sql = " INSERT INTO Authors (au_id, au_fName, "
sql = sql & "au_lName, phone, address, city, state)"
sql = sql & " VALUES('" & AuthorID & "','" & FName
sql = sql & "','" & LName & "','" & Phone
sql = sql & "','" & Address & "','" & City
sql = sql & "','" & State & "')"

' Execute the INSERT SQL
cnnPubs.Execute sql
intCount=1
End if
I am not clear where the 0 suffix is coming from in the following:
AuthorID=Request.Form("ID_0")
FName=Request.Form("fName_0")

That is what you typed in, I presume.

do you have any other suggestions?
 
J

Jack

Thanks for pointing that out. At a later part of the code, there is indeed
reference to the 0s. Regards.
 
M

Mark Schupp

Appending an index number to the field name is one way of keeping track of
multiple records on a single form.
For example:

First author on form would have: ID_0, fname_0, lname_0 ...
Second author: id_1, fname_1, lname_1

And so on. Have a look at the code that generates the form and you will
probably find a loop that creates each set of form fields.
 
J

Jack

Thanks for the clarity of the concept Mark. I saw later how the code keeps
track of multiple records in a single form. Is there any way of handling this
kind of problems? Just curious. Regards.
 
M

Mark Schupp

do you mean any "other" way for that kind of problem?

If you name all of the fields of the same type the same name (ie: "id"
instead of "id_0", "id_1", ...) then you can use array notation on the
server to extract the data. Or you can use the split function to break of
the field data into individual records (when field names are repeated the
data is sent in a comma separated string).

Form:

<input name="id" ....
<input name="lname" ...
<input name="id" ....
<input name="lname" ...
<input name="id" ....
<input name="lname" ...

Script
For i = 0 to Request.Form("id").Count
id = Request.Form("id")(i)
lname=Request.Form("lname")(i)

....

Next
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top