I'm trying to use checkboxes to add users to a specific group but I'm having trouble figuring exactly how the logic works. The list of users is pulled from a sql statement and is echo'd. I would like to display a checkbox beside each name, and if the box is checked that user will be added to the list using implode so I can store the members in one column.
Here is the output that displays a list containing users, their location, and a checkbox. I'd like to be able to select the checkbox and then add them to the group based on their userID($friendNum).
Update: the checkboxes are working and properly entering into the databse but the inputs in the first form aren't being entered. (title, description, date, location)
$myUsername = $_SESSION['userid'];
if(isset($myUsername)){
echo '<table><form method="post" action="event.php" name="groupInvite">
<tr><td> Event Title:</td><td> <input type="text" name="eventTitle" /></td></tr>
<tr><td>Event Description:</td><td> <textarea name="eventDescription" /></textarea></td></tr>
<tr><td>Event Date: </td><td><input type="text" name="eventDate" /></td></tr>
<tr><td>Event Location:</td><td><input type="text" name="eventLocation" /></td></tr></table>
<table><tr><td>Username </td><td> Location</td><td>Invite To Event</td></tr>';
$friends = mysql_query("SELECT userid1 as friendId FROM friends WHERE userid2 = $myUsername AND friendstatus = 1
UNION SELECT userid2 as friendId FROM friends WHERE userid1 = $myUsername AND friendstatus = 1");
while($friend = mysql_fetch_array($friends)){
$userID = $friend['friendId'];
$friendNum = mysql_query("select * from users where userid = $userID");
$friendID = mysql_fetch_array($friendNum);
$userLocation = mysql_query("select * from userinfo where userid='$userID'");
$locationResult = mysql_fetch_array($userLocation);
$locationResultArray = $locationResult['userlocation'];
$locationExplode = explode("~","$locationResultArray");
echo '<tr>
<td><a href="profile.php?userid=' . $friendID['userid'] . '">' . $friendID['username'] . '</a></td>
<td>' . $locationExplode[0] . ', ' . $locationExplode[1] . '</td>
<td><input type="checkbox" name="friendID[]" value='.$friendID['userid'].' /></td></tr>';
}
echo '<tr><td> <input type="submit" name="eventSubmit" value="Create Event" />
</td></tr>
</form></table>';
}
if(isset($_POST['eventSubmit'])){
$userList = implode("~",$_POST['friendID']);
$sql = "INSERT INTO events VALUES('$userList',...)";
$result = mysql_query($sql);
echo "Event Created"; //just used for testing purposes
}
}