need help - survey voting

Reply

Join Date: Oct 2009
Posts: 11
Reputation: wayz1229 is an unknown quantity at this point 
Solved Threads: 0
wayz1229 wayz1229 is offline Offline
Newbie Poster

need help - survey voting

 
0
  #1
Nov 8th, 2009
i'm having problem with survey script and voting function. can anyone please help me out.. the script only accept the last question's answer and update the database = acount+1.

script to dislay survey:
  1. <?php
  2.  
  3. echo "<form action='vote.php' method=post>
  4. <table width='300' border='0' cellspacing='0' cellpadding='0' align='center'>";
  5.  
  6. $query1 = "SELECT * FROM questions";
  7. $result1 = mysql_query($query1)or die("ERROR: $query.".mysql_error());
  8.  
  9. $num_row=mysql_num_rows($result1);
  10.  
  11. $i=1;
  12.  
  13. while($i<$num_row){
  14.  
  15. while ($row1 = mysql_fetch_array($result1)) {
  16.  
  17. $qid = $row1['qid'];
  18. $qtitle = $row1['qtitle'];
  19.  
  20. $query2 = "SELECT * FROM answers WHERE qid='$qid'";
  21. $result2 = mysql_query($query2) or die("ERROR: $query.".mysql_error());
  22.  
  23. echo "<tr>
  24. <td width='300' align='left'><p>".$i.". ".$qtitle."</p></td>
  25. </tr>";
  26.  
  27. while ($row2 = mysql_fetch_array($result2)) {
  28.  
  29. $aid = $row2['aid'];
  30. $atitle = $row2['atitle'];
  31.  
  32. echo "<tr>
  33. <td width='300' align='left'><input type = radio name =aid value = '".$aid."'><font>".$atitle."</font></input><br></p></td>
  34. </tr>";
  35. }
  36.  
  37. echo "<input type = hidden name = qid value = '".$qid."'>";
  38. echo "<br />";
  39. $i++;
  40.  
  41. }
  42. }
  43.  
  44. echo "<td><br><br></td><tr>
  45. <td width='300' align='center'><input type = submit name = submit value = 'Submit'></td>
  46. </tr>
  47. </table>
  48. </form>";
  49.  
  50. }
  51. }
  52. // close connection
  53. mysql_close();
  54.  
  55. ?>


voting script:
  1. <?php
  2. if (isset($_COOKIE) && !empty($_COOKIE)) {
  3. if ($_COOKIE['lastpoll'] && $_COOKIE['lastpoll'] == $_POST['qid']) {
  4. echo '<script>alert("You have already voted. Thank You !!!");</script>';
  5. echo '<script>location.replace("trysurvey.php");</script>';
  6. exit();
  7. }
  8. }
  9. // set cookie
  10. setCookie('lastpoll', $_POST['qid'], time() + 2592000);
  11.  
  12.  
  13. if (isset($_POST['submit'])) {
  14.  
  15. if (!isset($_POST['aid'])) {
  16. echo '<script>alert("Please select one of the available choices.");</script>';
  17. echo '<script>history.back(1);</script>';
  18. }
  19. else{
  20.  
  21. require_once('config.php');
  22.  
  23. $aid=$_POST['aid'];
  24. $qid=$_POST['qid'];
  25.  
  26. // update vote counter
  27. $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid' AND qid = '$qid'";
  28. $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
  29.  
  30. }
  31.  
  32. // close connection
  33. mysql_close();
  34.  
  35.  
  36. // print success message
  37. echo '<script>alert("Your have successfully voted.");</script>';
  38. echo '<script>location.replace("trysurvey.php");</script>';
  39. }
  40. else {
  41. echo '<script>alert("Unable to submit your Vote. Please try again !!!");</script>';
  42. echo '<script>history.back(1);</script>';
  43. }
  44.  
  45. ?>

please help.....
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC