I am trying to get multiple rows to insert into a mysql table from a form that allows for multiple checkboxes.
This is the form:
<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 />';
}
?>
This is the 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')");
}
}
?>
It is inserting one line into the database but not multiple lines. If I echo the username after the foreach, multiple usernames are showing.
If anyone could help I would appreciate it.
var_dump($combined);
– Travesty3 May 18 '12 at 18:11You have an error in your query near...
? – Salman A May 18 '12 at 18:35