Hello,
Despite much searching, I've hit a wall with trying to get a varying number of records inserted into a database.
Here's what I'm trying to do.....
I'm building an online sign on site for races at a sailing club. For the sign on page, I want to make it possible for racers to sign on for either one or all the races happening on a day. Here's the form.....
<form action="" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Helm:</td>
<td><select name="helm">
<option value="">Please Select....</option>
<?php
do {
?>
<option value="<?php echo $row_sailors['name']?>"><?php echo $row_sailors['name']?></option>
<?php
} while ($row_sailors = mysql_fetch_assoc($sailors));
$rows = mysql_num_rows($sailors);
if($rows > 0) {
mysql_data_seek($sailors, 0);
$row_sailors = mysql_fetch_assoc($sailors);
}
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Crew:</td>
<td><select name="crew">
<option value="">Please Select....</option>
<?php
do {
?>
<option value="<?php echo $row_crew['name']?>"><?php echo $row_crew['name']?></option>
<?php
} while ($row_crew = mysql_fetch_assoc($crew));
$rows = mysql_num_rows($crew);
if($rows > 0) {
mysql_data_seek($crew, 0);
$row_crew = mysql_fetch_assoc($crew);
}
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Boat:</td>
<td><select name="boat">
<option value="">Please Select....</option>
<?php
do {
?>
<option value="<?php echo $row_boats['boat_type']?>"><?php echo $row_boats['boat_type']?></option>
<?php
} while ($row_boats = mysql_fetch_assoc($boats));
$rows = mysql_num_rows($boats);
if($rows > 0) {
mysql_data_seek($boats, 0);
$row_boats = mysql_fetch_assoc($boats);
}
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sail Number:</td>
<td><input type="text" name="sailnumber" value="" size="20" /></td></tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Sign On" /></td>
</tr>
</table>
<input name="racecrewid" type="hidden" value="<?php echo $_SESSION['raceteam']; ?>" />
<input type="hidden" name="raceid" value="<?php echo $row_racestoday['raceunique']; ?>" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
Now the bit I'm stuck on - when there is more than one race on a day, I can't get the INSERT INTO query to add a record for each race occurence - for example, there are 3 races on any given day, the racers want to sign on for all 3 races in one hit, therefore the code below loops 3 times with the crew info but changes the race id. I haven't yet added the option for people to sign on for one or all races - I'm trying to get this bit to work first!
Here's the insert code
<?
if (isset($_POST['submit']));{
do {
$raceid = $_POST['raceid'];
$steerer = $_POST['helm'];
$swimmer = $_POST['crew'];
$boatywoaty = $_POST['boat'];
$knowtheboat = $_POST['sailnumber'];
$todaysteam = $_POST['racecrewid'];
$query = "INSERT INTO tblcompetitors (helm, crew, boat, sailnumber, raceid, raceteamid) VALUES('$steerer','$swimmer', '$boatywoaty', '$knowtheboat', '$raceid', '$todaysteam')";
mysql_select_db($database_sailingdb, $sailingdb);
mysql_query($query) or die(mysql_error("still not working grrr!!"));
} while ($row_racestoday = mysql_fetch_assoc($racestoday));
}
?>
As far as I can tell, it isn't looping. Having tried various for / foreach loops but just can't get it to work. It inserts the correct details once but leaves the raceid column blank.
Any help gratefully received!
Thanks in advance
Dave