开发者

Trying to get multiple radio buttons passed through form

I have a while loop printing multiple checkboxes..I changed them to checkboxes instead of radio buttons.. now all I want to do is pass the names of all those checkboxes to my vote.php file. If I give my checkbox in my loop a simple name and carry that over to my vote.php which handles all my POST data, it only carries over my last selection.. I want all of my selections. I cleaned my code up for you guys a little bit.

Tell me where I am going wrong here.. here is m开发者_开发百科y initial code printing the buttons..

        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;

    }

?>

All I really want to do is submit multiple people to a vote and not just one person. Thoughts? Thanks guys!

Here is my code for my checkboxes..

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

Now here is the code that handles these checkboxes.. I didn't write this code and I am having to debug it, so any help is appreciated.

$candidate_id = safeEscapeString(qsrequest(candidateOne));

This code right now handles a string, not a variable. What's the process in having a variable represent multiple checkboxes on the other file while recording them on here?


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

You must change the 'name' as you have changed the 'value' in the loop by a variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜