我的代码有问题:
$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());
}
如果我只在表单中填写我的一个输入并点击提交,它会提交一个但还有 16 个空白记录,其中只有 playlist_id 和其他列为空白。如果我填写了 5 列,它会提交它们,但也会提交 11 个空白以及 fk_id
我的表格布局是这样的:
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>';
并继续前进大约 10 个。