Skip to main content
December 20, 2007
Question

Insert multiple rows into database based on form data entry using PHP & mySQL

  • December 20, 2007
  • 3 replies
  • 743 views
I have tried to find tutorial about this but still no luck.
Here, i would like to get some help...

i have 1 table that contain a list of property.
Then, make a recordset (rsProperty) and list it using recordset repeat region (Server behaviour > Repeat Region)

How do i loop OR transfer OR copy all the result from rsProperty into 1 hidden form and using INSERT statement

=============
sprintf("INSERT INTO.....
=============

into new table rsProperty2 row by row???

example what i want to do:
rsProperty2
001
002
003
004

==========
Code that i have tried to make:
==========

for ($i=0; $i<$totalRows_rsProperty; $i++) {
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO multiple_property (property) VALUES (%s)",
GetSQLValueString($_POST['hiddenField'], "int"));

mysql_select_db($database_rental, $rental);
$Result1 = mysql_query($insertSQL, $rental) or die(mysql_error()); }
}

Result from this code:
table.Property
001
001
001
001
==========
The looping work but only get 1 row from repeat region, missing 002,003,004...
What i want is to get all the result, 001,002,003,004

Please somebody help me...
This topic has been closed for replies.

3 replies

Inspiring
December 21, 2007
"Kai?" <webforumsuser@macromedia.com> wrote in message
news:fkh410$muj$1@forums.macromedia.com...
> yes....any idea???

Create a form with hidden fields or checkboxes with the primary key for your
table
In the list

See the Insert ... Select syntax
http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

INSERT INTO othertable(field1,field2) SELECT field1,field2 FROM thetable
WHERE id IN (varIds)



December 21, 2007
yes....any idea???
Participant
December 21, 2007
So you want to run a query and then copy all results into another table?