2011-08-05 43 views
0

我有一個while循環打印多個複選框..我將它們改爲checkbox而不是單選按鈕..現在我想要做的就是將所有這些複選框的名稱傳遞給我的投票.php文件。如果我在我的循環中給我的複選框輸入一個簡單的名字,然後將它傳遞給我的vote.php,它處理我所有的POST數據,它只會繼續我最後的選擇。我想要我所有的選擇。我清理了我的代碼給你們一點點。試圖讓多個單選按鈕通過表單

告訴我在哪裏,我錯了here..here正在打印按鈕我最初的代碼..

 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>"; 

現在,這裏是處理這些checkboxes..I沒有寫這個代碼,我有調試它的代碼,所以任何幫助讚賞。

$candidate_id = safeEscapeString(qsrequest(candidateOne)); 

此代碼現在處理一個字符串,而不是一個變量。有什麼過程中有一個變量代表在另一個文件上的多個複選框,而在這裏錄製它們?

+0

這個問題有點令人困惑,因爲你顯示了你所有的服務器端代碼,沒有關於單選按鈕。如果您嘗試從表單輸入中收集多個人,請使用複選框而不是單選按鈕。 – kinakuta

+0

你可以整理你的源代碼,所以它更容易閱讀,請。 –

+0

對不起,我把它清理了一下。 – wowzuzz

回答

1
print "<td width=\"4\" valign=\"top\"><input type=\"radio\" name=\"candidateOne\" id=\"candidate\" value=$id></td>"; 

您必須更改'名稱',因爲您已通過變量更改循環中的'值'。

+0

如何每次給變量賦予一個不同的名字值?我只是困惑於候選人將設置爲什麼? – wowzuzz