我有一个while循环打印多个复选框..我将它们更改为复选框而不是单选按钮..现在我想要做的就是将所有这些复选框的名称传递给我的vote.php
文件。如果我在循环中给我的复选框一个简单的名称并将其传递给处理我所有POST数据的vote.php
,它只会延续我最后的选择..我想要我所有的选择。我为你们清理了一些代码。
告诉我这里的错误在哪里..这是我打印按钮的初始代码..
while($row_nominee=mysql_fetch_array($result_nominee)){
$id = $row_nominee[0];
//print "$level";
$prefix = $row_nominee[1];
$fname = $row_nominee[2];
$lname = $row_nominee[3];
$suffix = $row_nominee[4];
$city = $row_nominee[5];
$state = $row_nominee[6];
$zip = $row_nominee[7];
$bio = $row_nominee[8];
$level = $row_nominee[10];
$name = $prefix . " " . $fname . " " . $lname;
$address = $city . " " . $state . " " . $zip;
//print "$voted";
print "<tr>";
print "<td width=\"4\" valign=\"top\"><input type=\"checkbox\" name=\"candidateOne\" id=\"candidate\" value=$id></td>";
print "<td valign=\"top\"><FONT face=Tahoma,Arial,Helv size=-1><b>Name:</b> <font color=\"#ff0000\">$name</font><br><b>Hometown:</b> $address<br><b>Bio:<br /></b> $bio</font></td>";
print "</tr>";
}
?>
//now here is my vote.php file which handles the checkboxes.
//get the contents from the vote ballot Form
$voter_id = safeEscapeString(qsrequest(voter));
$candidate_id = safeEscapeString(qsrequest(candidateOne));
//print "$voter_id and $candidate_id";
include '../../sql/usagym_connection.php';
if(qsrequest(correct))
{
$voter_id1= safeEscapeString(qsrequest(voter1));
$candidate_id1= safeEscapeString(qsrequest(candidate1));
$votes1= safeEscapeString(qsrequest(votes1));
$votes1 += 1;
$sql_voter = "update stateChair_voters set voted='Y' where (usagnum='$voter_id1')";
//print "$sql_voter<br>";
$result_voter = mysql_query($sql_voter, $link) or die("Invalid query2");
$update_candidate = "update stateChair_nominees set votes=$votes1 where (id=$candidate_id1)";
//print "$update_candidate<br>";
$result_update = mysql_query($update_candidate, $link) or die("Invalid query3");
//print "Total votes is $votes1.";
header( "Location: vote_thanks.html");
exit;
}
else
{
//connect the database
$sql_candidate = "select id, prefix, fname, lname, suffix, city, state, zip, bio, votes from stateChair_nominees where id=$candidate_id";
$result_candidate = mysql_query($sql_candidate, $link) or die("Invalid query1". mysql_error());
while($row_candidate=mysql_fetch_array($result_candidate)){
$id = $row_candidate[0];
$prefix = $row_candidate[1];
$fname = $row_candidate[2];
$lname = $row_candidate[3];
$suffix = $row_candidate[4];
$city = $row_candidate[5];
$state = $row_candidate[6];
$zip = $row_candidate[7];
$bio = $row_candidate[8];
$votes = $row_candidate[9];
$name = $prefix . " " . $fname . " " . $lname;
$address = $city . " " . $state . " " . $zip;
}
?>
我真正想做的就是提交多人投票,而不仅仅是一个人。思考?谢谢你们!
这是我的复选框的代码..
print "<td width=\"4\" valign=\"top\"><input type=\"checkbox\" name=\"candidateOne\" id=\"candidate\" value=$id></td>";
现在这里是处理这些复选框的代码..我没有编写此代码,我不得不调试它,所以任何帮助表示赞赏。
$candidate_id = safeEscapeString(qsrequest(candidateOne));
此代码现在处理字符串,而不是变量。将变量表示在另一个文件上的多个复选框,同时在这里记录它们的过程是什么?
答案 0 :(得分:1)
print "<td width=\"4\" valign=\"top\"><input type=\"radio\" name=\"candidateOne\" id=\"candidate\" value=$id></td>";
您必须更改“名称”,因为您已通过变量更改循环中的“值”。