そのため、スレッドのエントリごとに投票システムをまとめようとしています。各エントリには一連のラジオ ボタン (1、2、3) があり、下部に送信ボタンがあります。投票する人には、エントリごとに 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!";
}
最後のエントリが選択されていて、他のエントリが選択されていない場合でも、すべてのエントリが選択されていると見なされる場合、最後のエントリを除いて機能します