Comma delimited array into DB problems

A

Arne

From: "Arne de Booij" <[email protected]>
Subject: Comma delimited array into DB problems
Date: 9. februar 2004 10:39

Hi,

I have an asp page that takes input from a form on the previous page,
puts that into an array and inserts the array into SQL server.

Now here is the problem:

The form on the page where the user can enter information contains a
dynamic amount of text boxes with the same name. So when the user
submits their entry, I get a comma delimited string.

e.g. First entry, Second entry, Third entry

The problem comes when a user enters a comma in the text field

e.g. First entry, with a comma, Second entry, Third Entry.

My code will put "with a comma" into a different row in the DB than
"First entry" because of the comma in the string.

Any ideas on how to solve this?


CODE (somewhat simplified)

Detailsvar = request("details")
details = Replace(Detailsvar, "'", "''") 'array

Dim deArray
deArray = Split(details, ", ")

FOR i = Lbound(deArray) TO Ubound(deArray)
DB.Execute("sp_insert_ratings '" & deArray(i) & "'")
NEXT

Arne
 
A

Aaron Bertrand - MVP

You could treat the form element as a collection, rather than as a comma
separated string.

<form method=post>
<input type=text name=x value="a, b">
<input type=text name=x value="c">
<input type=text name=x value="d">
<input type=submit>
</form>

<%
for i = 1 to request.form("x").count
response.write request.form("x")(i) & "<br>"
next
%>
 
A

Arne de Booij

The form on the page where the user can enter information contains a
dynamic amount of text boxes with the same name.

e.g.

<FORM ...>
Textbox1: First comment
<BR>
Textbox1: Second comment
<BR>
Textbox1: Third comment
<BR>
</FORM>

When you submit this and request it on the next page
(request("Textbox1")) you get the string: First comment, Second comment,
Third comment.

So it is basically automatic.
 
A

Arne

Hi Aaron,

your comment sent me in the right direction. I was able to make minor
adjustments to the entire code to get it to work.

thanks!
___________
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top