So I am trying to put together a voting system for each entry of a thread. Each entry gets a set of radio buttons (1, 2, 3) and a submit button is at the bottom. I want people voting to make sure they select one of the three radio buttons for each entry. I thought my code was working, but it's not. The last entry if it is selected, and all others aren't, it still says that its fine. But if I don't select the last entry it is working.
<form action="vote.php" method="POST" name="form1">
<? $sql = "SELECT * FROM contest_entries WHERE contest_id='$contest_id' ORDER BY id desc";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
while ($list = mysql_fetch_assoc($result)) { $username=$list['username'];
$date=$list['date_entered'];
$pl_holder=$list['place_holder1'];
$contest_entry_id=$list['id'];
echo "1<input name='attending[$contest_entry_id]' type='radio' value='1'>
2<input name='attending[$contest_entry_id]' type='radio' value='2'>
3 <input name='attending[$contest_entry_id]' type='radio' value='3'> />";
}?>
<input type="submit" name="submit2" id="submit" value="Submit" />
So then on my vote.php page after hitting submit:
foreach($_POST['contest_entry_id'] as $key => $something) {
$example = $_POST['attending'][$key];
} if (!isset($example)) {
echo "You need to vote for all entries";
exit();
}else{
echo "success!";
}
It works except for the last entry, if the last entry is selected and others aren't it still thinks all entries have been selected