| Author |
Topic Search Topic Options
|
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Topic: insert multiple rows Posted: 28 January 2008 at 1:00pm |
Hi,
What's the simplest way to insert multiple rows of data from one form into a database?
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 28 January 2008 at 1:36pm |
|
Not sure what type of form you are talking about. Depending on the DB you can simply paste from e.g. Excel to SQL. If it's a CSV you can write a little insert statement like Insert into table1 (col1,col2,col3) Select col1,col2,col3 from csvprovider
Again, it really depends where your data is coming from.
|
|
|
 |
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Posted: 28 January 2008 at 3:13pm |
It is coming from a webform, where user should add 5 rows per submit.
like in tell a friend form, the user enters up to 5 email addresses, each should be inserted in a new row in the table,
|
 |
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Posted: 28 January 2008 at 3:15pm |
michael wrote:
If it's a CSV you can write a little insert statement like Insert into table1 (col1,col2,col3) Select col1,col2,col3 from csvprovider
|
is there any example for this? if I want to insert from a csv file on server?
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 28 January 2008 at 5:53pm |
|
If you use classic ASP you would have to parse the file and read it in. Or you can setup a DSN to that CSV file and do basic SQL queries with it.
To insert from a web form into 5 different rows, you would just Request.Form each field and concatenate to a sql string, of course making sure each field is populated.
|
|
|
 |
Scott07
Groupie
Joined: 04 July 2002
Location: United Kingdom
Status: Offline
Points: 43
|
Post Options
Thanks(0)
Quote Reply
Posted: 17 February 2008 at 3:15pm |
|
If the database is mysql then you can run one insert that creates more than one record like
insert into table(col) values('bob'), ('jim'), ('ted');
(though double check the syntax as that might not be right)
|
|
|
 |
alemcherry
Newbie
Joined: 20 January 2008
Status: Offline
Points: 25
|
Post Options
Thanks(0)
Quote Reply
Posted: 02 March 2008 at 8:09pm |
|
insert into tablename (col1, col2) values (val11, val12) (val21, val22) (val31, val33)
|
 |
ffffffrabbit
Newbie
Joined: 11 February 2011
Location: USA
Status: Offline
Points: 1
|
Post Options
Thanks(0)
Quote Reply
Posted: 11 February 2011 at 4:01pm |
Classic ASP how do I do this:
> insert into tablename (col1, col2) values (val11, val12) (val21, val22) (val31, val33)
[CODE] < ="utf-8"><FORM METHOD="POST" ACTION="data_in.asp" NAME="FORMNAME"> ..... do while Not rs.eof %> <input type="hidden" value="<%=rs("value_a" Name="VALUEA"> <input type="text" name="TEXT_A"> < ="utf-8"><input type="text" name="TEXT_B"> < ="utf-8"><input type="text" name="TEXT_C">
<% rs.MoveNext loop rs.Close set rs = nothing %> </FORM>
< ="utf-8">[CODE] < ="utf-8">
|
 |