0

使用以下代码,我只将第一行放入数据库。看了很多例子,但我仍然看不出我哪里出错了。

// 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();
?>

谢谢。

4

3 回答 3

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
于 2013-01-25T03:45:58.553 回答
0

你没有关闭 foreach 循环,你错过了一个}.

于 2013-01-25T03:44:59.867 回答
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();
?>
于 2013-01-25T03:47:16.493 回答