Hi,
I'm trying to insert times for competitors in a race using one form which is built dynamically depending on how many competitors there are the code for the form is below...
form action="inputtimesstep3.php" method="post" name="racetimes">
<table align="center" border="1">
<tr align="center" valign="middle"><strong>
<td rowspan="2">Race Number</td>
<td rowspan="2">Start Time</td>
<td rowspan="2">Boat</td>
<td rowspan="2">Sail Number</td>
<td rowspan="2">Helm</td>
<td rowspan="2">Crew</td>
<td colspan="3">Time</td>
<td rowspan="2">Laps</td></strong>
</tr>
<tr align="center" valign="middle">
<td>Hours</td><td >Mins</td><td>Secs</td>
</tr>
<?php do { ?><tr align="center">
<td>
<input name="rnum" type="hidden" value="<?php echo $row_competitors['race_id']; ?>" size="5"/><?php echo $row_competitors['race_no']; ?></td>
<td>
<?php echo $row_competitors['starting_at']; ?>
</td>
<td>
<?php echo $row_competitors['whichboat']; ?>
</td>
<td>
<?php echo $row_competitors['sail_no']; ?>
</td>
<td>
<input name="helmysteers[]" type="hidden" value="<?php echo $row_competitors['racecrewpeeps']; ?>" /><?php echo $row_competitors['personhelm']; ?>
</td>
<td>
<?php echo $row_competitors['personcrew']; ?>
</td>
<td>
<input name="timetheytookhrs[]" type="text" value="" size="5"/></td>
<td><input name="timetheytookmins[]" type="text" value="" size="5"/></td>
<td><input name="timetheytooksecs[]" type="text" value="" size="5"/></td>
<td>
<input name="lapstheydid[]" type="text" value="" size="5"/></td></tr>
<?php } while ($row_competitors = mysql_fetch_assoc($competitors)); ?></table>
<p align="center"> <input type="submit" value="Enter Times"/></p>
</form>
The problem I've got is getting this information to submit into the table. I've tried using a foreach() loop but only get one column filled, I fiddled around with this some more but ended up with multiple entries (fake race with 4 entrants gave me 1000+ records, oops!!). I've also tried using
<?
$racywacy = $_POST['rnum'];
$hrstaken = $_POST['timetheytookhrs'];
$minstaken = $_POST['timetheytookmins'];
$secstaken = $_POST['timetheytooksecs'];
$lapping = $_POST['lapstheydid'];
$crew = $_POST['helmysteers'];
do { $i=$i+1;
$rwy = $racywacy;
$htkn[$i] = $hrstaken;
$mtkn[$i] = $minstaken;
$stkn[$i] = $secstaken;
$lpping[$i] = $lapping;
$crw[$i] = $crew;
$query = "INSERT INTO tblresults (race_id, boatcrewid, hours, mins, secs, laps) VALUES ('$rwy', '$crw', '$htkn', '$mtkn', '$stkn', '$lpping')";
mysql_select_db($database_sailingdb, $sailingdb);
$result = mysql_query($query, $sailingdb) or die(mysql_error());
} while ($row_competitors = mysql_fetch_assoc($competitors));
and a for() loop
<?php for ($i=0; $i<=$numb; $i++) { //insert query goes here, $numb is the total rows in the select query which builds the original form.
} ?>
All I seem to get into the db at the mo is one race number and a variable number of rows of 0's - not matching the number of competitors in the race though...
Anyone have any suggestions of how to get this to go????
Cheers
Dave