簡體   English   中英

試圖通過表單傳遞多個單選按鈕

[英]Trying to get multiple radio buttons passed through form

我有一陣子循環打印多個復選框..我將它們更改為復選框而不是單選按鈕..現在我要做的就是將所有這些復選框的名稱傳遞給我的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));

現在,此代碼可以處理字符串,而不是變量。 在此處將變量記錄時,讓變量代表另一個文件上的多個復選框的過程是什么?

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

您必須更改“名稱”,因為您已經通過變量在循環中更改了“值”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM