943,945 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 332
  • PHP RSS
Nov 8th, 2009
0

need help - survey voting

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  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:
PHP Syntax (Toggle Plain Text)
  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.....
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wayz1229 is offline Offline
11 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: session variable problem
Next Thread in PHP Forum Timeline: refresh page one time only..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC