【发布时间】:2013-05-20 03:42:56
【问题描述】:
所以我试图为线程的每个条目组合一个投票系统。每个条目都有一组单选按钮(1、2、3),底部有一个提交按钮。我希望人们投票以确保他们为每个条目选择三个单选按钮之一。我以为我的代码可以正常工作,但事实并非如此。如果选择了最后一个条目,而其他所有条目都没有,它仍然说它很好。但是,如果我不选择它正在工作的最后一个条目。
<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!";
}
除了最后一个条目外,如果最后一个条目被选中而其他条目没有被选中,它仍然认为所有条目都已被选中
【问题讨论】:
标签: php radio-button