使用以下代码我只获得数据库的第一行。 看了很多例子,但我仍然看不出我出错的地方。
// one box for each //
<input class="bginput" name="album_name[]" size="30" type="text">
<imput type="submit" Value="submit">
<?PHP
foreach($_POST['artist_id'] as $row=>$val) {
$artist_id = mysql_real_escape_string($val);
$album_name = mysql_real_escape_string($_POST['album_name'][$row]);
$image_album_id = mysql_real_escape_string($_POST['image_album_id'][$row]);
$track = mysql_real_escape_string($_POST['track'][$row]);
$song_name = mysql_real_escape_string($_POST['song_name'][$row]);
$duration = mysql_real_escape_string($_POST['duration'][$row]);
$sql = mysql_query("INSERT INTO songs (`image_album_id`, `member_id`, `artist_id`, `album_name`, `track`, `song_name`, `duration`, `timestamp`)
VALUES ('$image_album_id', '".$_SESSION['member_id']."','$artist_id','$album_name', '$track', '$song_name', '$duration', UNIX_TIMESTAMP() )") or die(mysql_error());
header ('Location: song_details_add.php?success');
exit();
?>
感谢。
答案 0 :(得分:1)
你似乎忘了关闭你的foreach循环:
foreach($_POST['artist_id'] as $row=>$val) {
$artist_id = mysql_real_escape_string($val);
$album_name = mysql_real_escape_string($_POST['album_name'][$row]);
$image_album_id = mysql_real_escape_string($_POST['image_album_id'][$row]);
$track = mysql_real_escape_string($_POST['track'][$row]);
$song_name = mysql_real_escape_string($_POST['song_name'][$row]);
$duration = mysql_real_escape_string($_POST['duration'][$row]);
$sql = mysql_query("INSERT INTO songs (`image_album_id`, `member_id`,`artist_id`, `album_name`, `track`, `song_name`, `duration`, `timestamp`)
VALUES ('$image_album_id', '".$_SESSION['member_id']."','$artist_id','$album_name', '$track', '$song_name', '$duration', UNIX_TIMESTAMP() )") or die(mysql_error());
} <---- missing
答案 1 :(得分:0)
你没有关闭foreach循环,你错过了}
。
答案 2 :(得分:0)
似乎缺少foreach
闭括号}
。但它应该抛出语法错误。如你所说它插入一行,我觉得你在重定向后关闭了}
。
试试这个
<?PHP
foreach($_POST['artist_id'] as $row=>$val) {
$artist_id = mysql_real_escape_string($val);
$album_name = mysql_real_escape_string($_POST['album_name'][$row]);
$image_album_id = mysql_real_escape_string($_POST['image_album_id'][$row]);
$track = mysql_real_escape_string($_POST['track'][$row]);
$song_name = mysql_real_escape_string($_POST['song_name'][$row]);
$duration = mysql_real_escape_string($_POST['duration'][$row]);
$sql = mysql_query("INSERT INTO songs (`image_album_id`, `member_id`, `artist_id`, `album_name`, `track`, `song_name`, `duration`, `timestamp`)
VALUES ('$image_album_id', '".$_SESSION['member_id']."','$artist_id','$album_name', '$track', '$song_name', '$duration', UNIX_TIMESTAMP() )") or die(mysql_error());
}
header ('Location: song_details_add.php?success');
exit();
?>