所以我试图把一个投票系统对线程的每个条目。每个条目都有一组单选按钮(1,2,3),提交按钮位于底部。我希望投票的人们确保他们为每个条目选择三个单选按钮中的一个。我认为我的代码正在工作,但事实并非如此。最后一个条目如果被选中,而其他所有条目都不是,它仍然会说它很好。但是,如果我不选择它正在工作的最后一个条目。如何确保至少有一个单选按钮每组中选择,PHP
<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" />
所以后来我vote.php页击中后提交:
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!";
}
它的工作原理除了最后一项,如果选择了最后一个条目,其它的是不是仍认为所有条目已被选中
非常感谢,它工作! –