2011-08-05 4 views
0

여러개의 체크 박스를 인쇄하는 while 루프가 있습니다. 라디오 버튼 대신 체크 박스를 변경했습니다. 모든 체크 박스의 이름을 투표에 전달하는 것입니다. .php 파일. 루프의 체크 박스에 간단한 이름을 지정하고 모든 POST 데이터를 처리하는 내 vote.php로 이동하면 마지막 선택 항목 만 전달됩니다. 모든 선택 항목을 원합니다. 나는 당신을 위해 나의 코드를 조금 청소했다. 내 최초의 코드는 버튼을 인쇄하는 잘못된 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이 코드를 작성하지 않았고 나는 그것을 디버깅하는 데 처리하는 코드는, 그래서 어떤 도움이다 고맙습니다.

이 코드는 변수가 아닌 문자열을 처리합니다. 변수를 여기에 기록하는 동안 다른 파일에 여러 확인란을 표시하는 과정은 무엇입니까?

+0

질문은 서버 측 코드를 모두 표시하고 라디오 버튼을 표시하지 않기 때문에 다소 혼란 스럽습니다. 양식 입력에서 둘 이상의 사용자를 수집하려는 경우 라디오 버튼 대신 확인란을 사용하십시오. – kinakuta

+0

소스 코드를 깔끔하게 정리하여 읽을 수 있도록하십시오. –

+0

죄송합니다. 조금 청소했습니다. – wowzuzz

답변

1

변수의 '값'을 변경하면 '이름'을 변경해야합니다.

+0

변수마다 매번 다른 이름 값을 부여하는 방법은 무엇입니까? 나는 $ 후보자가 무엇으로 설정 될 것인지 혼란 스럽다. – wowzuzz

관련 문제