I am using some code that I found posted on a previous thread to insert multiple rows of data when the form is submitted.
However, the code inserts a record even when no data has been entered for a particular row, and I would like to eliminate that from the code. What I would like to do is ensure that before a row is created, it has at least one field/column of information provided for that row.
So far I have tried enclosing the foreach statement with an if conditional, but I can't seem to find an argument that works.
revez2002
<?php
if (!isset($_POST['submit'])) {
echo '
<tr>
<td width=10></td>
<td class=main_content_02>Firstname</td>
<td class=main_content_02>Lastname</td>
<td class=main_content_02>Phone Number</td>
<td class=main_content_02>Email</td>
<td class=main_content_02>Team Number</td>
</tr>
';
for ($i = 1; $i <= 3; $i++) {
echo '
<tr>
<td width="10"></td>
<td class="lite_green_02"><input type="text" name="row['.$i.'][firstname]" size="10"></td>
<td class="lite_green_02"><input type="text" name="row['.$i.'][lastname]" size="10"></td>
<td class="lite_green_02"><input type="text" name="row['.$i.'][phone_number]" size="10"></td>
<td class="lite_green_02"><input type="text" name="row['.$i.'][email]" size="10"></td>
<td class="lite_green_02"><input type="text" name="row['.$i.'][team_number]" size="5"></td>
</tr>
';
}
echo '
<tr>
<td colspan="6" height="40" width="100%" align="center" valign="middle"><input type="submit" name="submit" value="Enter"></td>
</tr>
';
} else {
foreach ($_POST['row'] as $value) {
$sql = mysql_query("INSERT INTO TEST_ROSTER SET
roster_ID=NULL,
firstname='".$value['firstname']."',
lastname='".$value['lastname']."',
phone_number='".$value['phone_number']."',
email='".$value['email']."',
team_number='".$value['team_number']."',
created_by='$username'");
}
}
?>