Forum Moderators: coopster

Message Too Old, No Replies

Insert record into DB from a dynamic form

         

recsx

4:45 pm on Jun 13, 2004 (gmt 0)

10+ Year Member



Hi all,

Im trying to insert multiple records into a database.

I have a form that is generated from a mysql query, i then need to re-insert all these results as seperate rows into a different table but only processing the ones with a check box next to it.

Its basicly a batch processing form to process payment from clients.

Here is my current script (all i have now is the query to make the form)

---------------------------------------------


$query = mysql_query("SELECT * FROM clients",$mysql_ID) or die (mysql_error());
print "<CENTER>
<FORM NAME=\"form\" METHOD=\"post\" ACTION=\"$PHP_SELF\">
<TABLE WIDTH=\"770\" BORDER=\"1\" CELLPADDING=\"0\" CELLSPACING=\"0\"><TR>
<TD ALIGN=\"right\" COLSPAN=\"5\" CLASS=\"td1\">Check All<input type=\"checkbox\" onClick=\"CUA(this);\"><BR>
<INPUT TYPE=\"submit\" NAME=\"batch\" VALUE=\"Process Batch\"></TD></TR>
<TR>
<TD ALIGN=\"center\" CLASS=\"th1\">ID</TD>
<TD ALIGN=\"center\" CLASS=\"th1\">Client name</TD>
<TD ALIGN=\"center\" CLASS=\"th1\">Company Name</TD>
<TD ALIGN=\"center\" CLASS=\"th1\">Monthly Rate</TD>
<TD ALIGN=\"center\" CLASS=\"th1\">Batch</TD>";

// Declare Date and Time Format
$wday = date(l);
$month = date(F);
$mday = date(d);
$year = date(Y);
// End Date Time Format

while ($myrow = mysql_fetch_array($query)) {
print "<TR>
<TD>" . $myrow["clientID"] . "<INPUT TYPE=\"hidden\" NAME=\"clientID\" VALUE=\"" . $myrow["clientID"] . "\"><INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"" . $wday . $month . $mday . $year . "\"></TD>
<TD><A HREF=\"$PHP_SELF?clientID=" . $myrow["clientID"] . "\">" .$myrow["fname"] . " " . $myrow["lname"] . "</A></TD>
<TD>" . $myrow["cname"] . "</TD>
<TD>$" . $myrow["monthly_rate"] . "</TD>
<TD ALIGN=\"right\"><INPUT TYPE=\"checkbox\" NAME=\"" . $myrow["clientID"] . "\"></TR>
";
}
print "<TR><TD ALIGN=\"right\" COLSPAN=\"5\" CLASS=\"td1\">Check All<input type=\"checkbox\" onClick=\"CUA(this);\"><BR>
<INPUT TYPE=\"submit\" NAME=\"batch\" VALUE=\"Process Batch\"></TD></TR></TABLE></FORM></CENTER>";


----------------------------------------------------

is there a way to do this?

Im having trouble finding a way to insert each row as a different record into the database.

REMINDER:
This is just my query to display my list and not the INSERT code.

I need suggestions on how to do it.

Thanks

jatar_k

6:15 pm on Jun 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the way to do it would be to have a loop do your inserts

either foreach or while depending on what you are testing

inside your loop you would

- construct your insert query
- execute the query using mysql query
- repeat