我正在尝试从允许多个复选框的表单中将多行插入到 mysql 表中。
这是表格:
<input type='submit' name='invite-group' value='Invite To Group'>
<br />
<?php
$query2aac = mysql_query("SELECT * FROM follow WHERE yoozer1='$userdb1a' AND followaccept='Yes' ORDER BY yoozer2 DESC");
while($row2aac = mysql_fetch_array($query2aac))
{
$rowid = $row2aac['followid'];
$yoozer2aac = $row2aac['yoozer2'];
$yoozer2aacurl = strtolower($yoozer2aac);
$palurl = '<a href="http://www.bunchofus.com/fanpage/' . $yoozer2aacurl . '">' . $yoozer2aac . '</a>';
echo '<input type= "hidden" name = "id[]" value="' . $rowid . '"></input>';
echo '<input type= "checkbox" name = "friends[]" value="' . $yoozer2aac . '">' . $palurl . '</input><br />';
}
?>
这是php:
if ($submit)
{
$submit = $_POST['invite-group'];
$date1 = date("Y-m-d");
$lowername = strtolower($username);
$combined = $_POST['friends'];
foreach ($combined as $username)
{
$insert1 = mysql_query("INSERT INTO grprequest VALUES ('','$grpid3','$username','$myuser','$grprights3','$grpactive3')");
}
}
?>
它是在数据库中插入一行,而不是多行。如果我在 foreach 之后回显用户名,则会显示多个用户名。
如果有人可以提供帮助,我将不胜感激。