Im having a problem with my code:
$size = count($_POST['tv_id']);
$size = count($_POST['Season']);
$size = count($_POST['EpisodeNumber']);
$size = count($_POST['EpisodeName']);
$i = 0;
while ($i < $size) {
$Season = mysql_real_escape_string($_POST['tv_id'][$i]);
$Season = mysql_real_escape_string($_POST['Season'][$i]);
$EpisodeNumber= mysql_real_escape_string($_POST['EpisodeNumber'][$i]);
$EpisodeName= mysql_real_escape_string($_POST['EpisodeName'][$i]);
$sql="INSERT INTO tvshows SET fk_id = '".$fk_id."', tv_id ='".$tv_id."', Season ='".$Season."', EpisodeNumber='".$EpisodeNumber."', EpisodeName='".$EpisodeName."'";
$query = mysql_query($sql) or die(mysql_error());
}
If i fill just one of my inputs in my form and hit submit it submits that one one but also 16 blank records with just the playlist_id and the other columns blank. If i filled in 5 columns it would submit them but also 11 blanks along with just the fk_id
My table layout is like this:
echo '<tr>';
echo "<td><input type='hidden' name='tv_id[]' id='tv_id' value='' /></td>";
echo "<td><input type='text' name='Season[]' id='Season[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeNumber[]' id='EpisodeNumber[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeName[]' id='EpisodeName[]' value='' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td><input type='hidden' name='tv_id[]' id='tv_id' value='' /></td>";
echo "<td><input type='text' name='Season[]' id='Season[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeNumber[]' id='EpisodeNumber[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeName[]' id='EpisodeName[]' value='' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td><input type='hidden' name='tv_id[]' id='tv_id' value='' /></td>";
echo "<td><input type='text' name='Season[]' id='Season[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeNumber[]' id='EpisodeNumber[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeName[]' id='EpisodeName[]' value='' /></td>";
echo '</tr>';
echo '<tr>';
echo "<td><input type='hidden' name='tv_id[]' id='tv_id' value='' /></td>";
echo "<td><input type='text' name='Season[]' id='Season[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeNumber[]' id='EpisodeNumber[]' value='' /></td>";
echo "<td><input type='text' name='EpisodeName[]' id='EpisodeName[]' value='' /></td>";
echo '</tr>';
and keeps going for about another 10.
if($Season && $EpisodeNumber ....) // Insert
BTW, you should$size += ...
– Valky Dec 4 '12 at 23:50$size
variable, right? – DC_ Dec 4 '12 at 23:50$i
. Unless that part was left out, an error should be thrown because$i
always = 0 – Michael Garrison Dec 5 '12 at 0:13