What i'm trying to do is take a form block that auto generate the number of rows I need and have my sql statements insert it into my db using an array.
Here's what I have :
(The page where date, number of people and type is shown):
(The form page):PHP Code:Training/Event Update<br><br>
<FORM METHOD="POST" ACTION="do_addrecord.php">
Date (mm/dd/yyyy):<br>
<INPUT TYPE="text" NAME="date" SIZE=30><br><br>
Number of Members Present:<br>
<INPUT TYPE="text" NAME="num_ppl" SIZE=30><br><br>
Training Type:<br>
<INPUT TYPE="text" NAME="trg_type" SIZE=30><br><br>
<INPUT TYPE="submit" NAME="submit" VALUE="Go to next Step">
</FORM>
and here's the part where it's sopposed to use an array to feed the db but I'll be honest...I'm learning this off the web and out of books and not sure what's not ticking...PHP Code:<?php
$form_block = "
<FORM METHOD=\"POST\" ACTION=\"do_addrecord2.php\">
<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"$_POST[date]\">
<INPUT TYPE=\"hidden\" NAME=\"type\" VALUE=\"$_POST[trg_type]\">
<TABLE CELLSPACING=5 CELPADDING=5>
<TR>
<TH>Member Name</TH><TH>Helmet Number</TH><TH>Training Type</TH>
</TR>";
for ($i = 0; $i <$_POST[num_ppl]; $i++) {
$form_block .= "
<TR>
<TD ALIGN=CENTER><INPUT TYPE=\"text\" NAME=\"member_name[]\" SIZE=\"30\"></TD>
<TD ALIGN=CENTER><INPUT TYPE=\"text\" NAME=\"helmet_num[]\" SIZE=\"5\"></TD>
<TD ALIGN=CENTER><INPUT TYPE=\"text\" NAME=\"trg_type[]\" SIZE=\"30\" VALUE=\"$_POST[trg_type]\"></TD>
</TR>";
}
$form_block .= "
<TR>
<TD ALIGN=CENTER COLSPAN=3><INPUT TYPE=\"submit\" VALUE=\"Add Training Record\"></TD>
</TR>
</TABLE>
</FORM>";
?>
What I'm trying to have happen is on the 2nd page once all the names n helmet numbers are entered, they are fed to the db. the id field is an auto-increment as well. Other than using tables instead of CSS, any ideas?PHP Code:<?php
$db_name = "db";
$table_name = "table";
$connection = @mysql_connect("location", "name", "password") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
for ($i = 0; $i < count($_POST[num_ppl]); $i++) {
$sql = "INSERT INTO $table_name (id, date, member_name, helmet_num, trg_type)
VALUES ('$_POST[date][$i]', '$_POST[member_name][$i]', '$_POST[helmet_num][$i]', '$_POST[trg_type][$i]')";}
$result = @mysql_query($sql, $connection) or die(mysql_error());
?>





Reply With Quote