2015-02-02 2 views
0

라디오 버튼을 사용하여 데이터베이스에서 투표를 업데이트 할 수없는 이유를 알아 내려고하고 있습니다. 나는 코딩에 능숙하지 않지만 알아 내려고 최선을 다하고 있지만 지금은 운이 없다. die 귀하의 사용은 실행 후 오류를 던지고있다mysql 데이터베이스에서 +1 투표를 업데이트 할 수 없습니다.

<!doctype html> 
<html> 
    <head> 
    <title>vote3</title> 
    </head> 

    <body> 

<?php 


     $users_account = $_GET['users_account']; 
     $connect = mysqli_connect('localhost', 'root', 'password','surveytest'); 
     $query = "SELECT * FROM users_account WHERE username='archievald'"; 
     $q = mysqli_query($connect, $query); 
     while($row = mysqli_fetch_array($q)) { 
      $id = $row[0]; 
      $username = $row[1]; 
      $password = $row[2]; 
      $voted = $row[3]; 
      $acc_type = $row[4]; 

      echo "<h1>Is he good in english?</h1>"; 

      ?> 

      <table> 
      <form action="" method="POST"> 

     <?php 
      $questions = "SELECT * FROM questions WHERE pollid='test'"; 
     $q2 = mysqli_query($connect, $questions); 
     while($r = mysqli_fetch_array($q2)) { 
      $questions = $r[1]; 
      $votes = $r[2]; 
      $newvotes = $votes + 1; 
      $ip = $_SERVER['REMOTE_ADDR']; 
      echo '<tr><td>'.$questions.'</td><td> <input type="radio" name="polloption" value="'.$questions.'" </td></tr>'; 
      } 
      if (isset($_POST['vote'])) { 
       $polloption = $_POST['polloption']; 
       if ($polloption == "") { 
        die("You didnt select an option."); 
       } else { 
        mysqli_query($connect, "UPDATE questions SET votes = $newvotes WHERE questions='$polloption'"); 
        die("You voted successfully"); 
       } 
      } 
     } 
     ?> 
     <tr><td><input type="submit" name="vote" value="votes" /></td></tr> 
       </form> 
      </table> 

    </body> 
</html> 

까지 내가 주요 문제는 여기에 기억으로

mysqli_query($connect, "UPDATE questions SET votes = $newvotes WHERE questions='$polloption'"); 
         die("You voted successfully"); 
+2

그래서 당신이 얻고있는 오류는 무엇입니까 – Afsar

+0

나는 오류가 발생하지 않지만 그것은 MySQL 데이터베이스 행에 업데이 트가 나던. 그것도 여전히 0 카운트 – giglers

답변

1

변화

mysqli_query($connect, "UPDATE questions SET votes = $newvotes WHERE questions='$polloption'"); 
die("You voted successfully"); 

$con=mysqli_query($connect, "UPDATE questions SET votes = $newvotes WHERE questions='$polloption'"); 
if(!$con){ 
    die("Update Query failed"); 
}else{ 
    print("You voted successfully."); 
} 

에 , 아닌 좋습니다. mysqli or die, does it have to die?

희망 사항 : die의 사용법에 대해 자세히 읽어 볼 수 있습니다.

+0

쿼리가 실패하면 "You toted successfully"를 프린트하는 이유는 무엇입니까? – Darren

+0

아, 맞아. 내가 편집 –

+0

거기 우리가 가서, 더 잘보고 :) – Darren

관련 문제