Hello,
I want to create a form and insert multiple rows in my mysql database.
All my form processing to date with php has usually inserted just one row so
I am not sure how to do this.
What I want to make is a batch input form.
Lets say my database table contains fields named: data1, data2, data3, data4
In a form with a table I will have:
<tr>
<td><input type=’TEXT’ name=’dat1′ value = “<?php echo $dat1 ?>” size = ’10’ maxlength=’10’/></td></td>
<td><input type=’TEXT’ name=’dat2′ value = “<?php echo $dat2 ?>” size = ’10’ maxlength=’10’/></td></td>
<td><input type=’TEXT’ name=’dat3′ value = “<?php echo $dat3 ?>” size = ’10’ maxlength=’10’/></td></td>
<td><input type=’TEXT’ name=’dat4′ value = “<?php echo $dat4 ?>” size = ’10’ maxlength=’10’/></td></td>
</tr>
NOW this is one row – but I would like TEN rows to be input and after the ten rows another row that shows the
total of these ten rows – The total will also be INSERTED as on extra row in the mysql table.
I prefer to do what I can with php on the server side but I suspect I will have to use javascript as well to
generate the form ? and to calculate the totals ???.
— below is certainly a php problem not js but I leave it in for clarity of
my problem. —-
I want to send the form once with all ten rows and then INSERT them into my table.
To insert them I guess I use:
$sql = “INSERT INTO homes (data1,data2,data3,data4)
VALUES (‘$data1′,$data2′,$data3′,$data4’)”;
mysql_query($sql) or die(“could not execute INSERT query”);
BUT do I put this is a while () Loop ? so that I get all eleven rows inserted ???
I really need some help !
Thanks for any assistance you can give me.
David.