I have a form which coaches can enter in multiple pitchers for games. The form allows users to add rows as needed and looks like this:
<tr><td><select name="pitcherteam[]" size="1">
<option>PLEASE SELECT TEAM
<option>Team 1
<option>Team 2
<option>Team 3
</select></td><td>
<input type=text size=50 name="pitcher[]"></td><td>
<select name="pitcherage[]" size="1">
<option>AGE
<option>8
<option>9
</select></td>
<td><input type="text" size=3 name="pitcherpitches[]"></td></tr>
The php code I am using loops through the pitchers and if they are not blank does an insert into the mysql db:
$size_array = count($_POST['pitcher']);
for ($i=0; $i<$size_array; $i++){
if($_POST['pitcher'][$i] != ''){
$sql2="INSERT INTO pitchcounts (pitcherteam, pitcher, pitcherage, pitches)
VALUES
('$_POST[date]','$_POST[pitcherteam][$i]','$_POST[pitcher][$i]','
$_POST[pitcherage][$i]','$_POST[pitches][$i]')";
if (!mysqli_query($con,$sql2))
{
die('Error: ' . mysqli_error($con));
}
}
}
The loop is actually updating the db - BUT - instead of the values from the form - it's putting in zeros and array markers like this:
pitcherteam pitcher pitcherage pitches
Array[0] Array[0] 0 0
Array[1] Array[1] 0 0
Array[3] Array[3] 0 0
Any ideas on what's going on? Thanks!