Guest User

Untitled

a guest
Oct 29th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. <?
  2.  
  3. //////////////////////////////////////
  4. // set these variables for your MySQL
  5. $dbhost = 'localhost'; // usually localhost
  6. $dbuser = 'root'; // database username
  7. $dbpass = ''; // database password
  8. //////////////////////////////////////
  9.  
  10. $db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Could not connect to the database.');
  11. mysql_select_db('final10sport');
  12. die('gdhpdfoghdfopgh');
  13. $survey = $_GET['s'];
  14. $results = $_GET['r'];
  15. $user = $_SERVER['REMOTE_ADDR'];
  16. $cookie = $_COOKIE['survey'];
  17. $msg = '<![CDATA[&nbsp;]]>';
  18.  
  19. $xml = '<?xml version="1.0" ?>';
  20.  
  21. if($survey != '' && $results != '') {
  22. $query = "SELECT `vid` FROM `voters` WHERE `ip`='".$user."' AND `qid`=".$survey." LIMIT 1";
  23. $result = mysql_query($query);
  24.  
  25. if($cookie == $survey || mysql_num_rows($result) > 0) {
  26. $msg = "You already voted.";
  27. } else {
  28. $query2 = "UPDATE `responses` SET `votes`=`votes`+1 WHERE `rid`='".$results."' AND `qid`='".$survey."'";
  29. mysql_query($query2);
  30.  
  31. $query3 = "INSERT INTO `voters` (`qid`,`ip`) VALUES ('".$survey."','".$user."')";
  32. mysql_query($query3);
  33. }
  34. }
  35.  
  36. $stype = ($survey != '')? "2":"1";
  37. $query = ($survey != '')? "SELECT `qid`,`subject`,`question`,DATE_FORMAT(`questions`.`date`,'%b %e, %Y') as date FROM `questions` WHERE `qid` = '".$survey."' LIMIT 1":"SELECT `qid`,`subject`,`question`,DATE_FORMAT(`questions`.`date`,'%b %e, %Y') as date FROM `questions` WHERE `show` = 1 LIMIT 1";
  38. $result = mysql_query($query);
  39. $row = mysql_fetch_array($result);
  40.  
  41. $xml .= "<survey type='".$stype."' id='".$row['qid']."'>
  42. <date>".$row['date']."</date>
  43. <subj>".$row['subject']."</subj>
  44. <ques><![CDATA[".$row['question']."]]></ques>
  45. <responses>";
  46.  
  47. $query2 = "SELECT `rid`,`response`,`votes` FROM `responses` WHERE `qid` = ".$row['qid']." ORDER BY `rid` ASC";
  48. $result2 = mysql_query($query2);
  49.  
  50. while($row2 = mysql_fetch_array($result2)) {
  51. $xml .= "<resp id='".$row2['rid']."' votes='".$row2['votes']."'>".$row2['response']."</resp>";
  52. $tvotes += $row2['votes'];
  53. }
  54.  
  55. $xml .= " </responses>
  56. <votes>$tvotes</votes>
  57. <msg>$msg</msg>
  58. </survey>";
  59.  
  60. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  61. header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
  62. header("Cache-Control: no-cache, must-revalidate" );
  63. header("Pragma: no-cache" );
  64. header("Content-Type: text/xml; charset=utf-8");
  65. if($survey != '' && $results != '') header("Set-Cookie: survey=".$survey."; expires=".gmdate("D, d M Y H:i:s",strtotime("+1 month"))." GMT; path=/;");
  66.  
  67. echo $xml;
  68.  
  69. /*****************************
  70.  
  71. <survey type='' id=''>
  72. <date></date>
  73. <subj></subj>
  74. <ques></ques>
  75. <responses>
  76. <resp id='' votes=''></resp>
  77. ...
  78. </responses>
  79. <msg></msg>
  80. </survey>
  81.  
  82. ******************************/
  83.  
  84. ?>
Add Comment
Please, Sign In to add comment