Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. <?php
  2. $mysqli = new mysqli("localhost", "a3519_glenn", "Dontchoke1", "a3519_poll");
  3.  
  4. if ($mysqli->connect_errno) {
  5. printf("Connect failed: %s\n", $mysqli->connect_error);
  6. exit();
  7. }
  8.  
  9. function retrieveNumVotes($letter) {
  10. global $mysqli;
  11. if (!$result = $mysqli->query("SELECT * FROM legislative WHERE vote='$letter'")) {
  12. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  13. }
  14. $total = $result->num_rows;
  15. $result->close();
  16. return $total;
  17. }
  18.  
  19. function makePercentage($letter) {
  20. global $mysqli;
  21. if (!$result = $mysqli->query("SELECT * FROM legislative")) {
  22. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  23. }
  24. $total_votes = $result->num_rows;
  25. $result->close();
  26. if ($total_votes == 0) return '0%';
  27. $percent = round((float)retrieveNumVotes($letter)/$total_votes * 100).'%';
  28. return $percent;
  29. }
  30. ?>
  31. <!DOCTYPE html>
  32. <!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
  33. <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
  34. <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
  35. <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
  36. <?php include("includes/head.html"); ?>
  37. <body>
  38. <div class="container">
  39. <a name="top"></a><?php include("includes/loginbar.html"); ?>
  40. <div class="row">
  41. <div class="sixteen columns">
  42. <div id="banner"></div>
  43. </div>
  44. </div>
  45. <?php include("includes/navbar.html"); ?>
  46. <div class="row">
  47. <?php include("includes/leftside.html"); ?>
  48. <div class="ten columns"><div id="center-block">
  49. <h4>Voting</h4>
  50. <h3>Legislative</h3>
  51. <?php
  52. $form = '<form action="" method="POST">
  53. <input type="radio" name="vote" value="a" /><li>N/A - Legislator</li>
  54. <br />
  55. <input type="radio" name="vote" value="b" /><li>N/A - Organizer</li>
  56. <br />
  57. <input type="radio" name="vote" value="c" /><li>N/A - Website Staff</li>
  58. <br />
  59. <input type="submit" name="submit" value="Vote" />
  60. </form>';
  61. $ip_address = $_SERVER['REMOTE_ADDR'];
  62. $checkIP = $mysqli->query("SELECT * FROM legislative WHERE ip_address='$ip_address'");
  63.  
  64. if (isset($_POST['submit'])) {
  65. $ip_address = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']);
  66.  
  67. if (!$result = $mysqli->query("SELECT * FROM legislative WHERE ip_address='$ip_address'")) {
  68. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  69. }
  70.  
  71. if ($result->num_rows == 0) {
  72. $vote = $mysqli->real_escape_string($_POST['vote']);
  73. if (!$mysqli->query("INSERT INTO legislative (vote, ip_address) VALUES ('$vote', '$ip_address')")) {
  74. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  75. } else {
  76. echo '<p>Success</p>';
  77. }
  78. }
  79. $result->close();
  80. }
  81.  
  82. if ($checkIP->num_rows == 0) {
  83. echo $form;
  84. } else {
  85. echo '<p>You have already voted</p>';
  86. }
  87.  
  88. echo '<li>N/A - Legislator - '.retrieveNumVotes('a').' votes ('.makePercentage('a').')<br /></li>';
  89. echo '<li>N/A - Organizer - '.retrieveNumVotes('b').' votes ('.makePercentage('b').')<br /></li>';
  90. echo '<li>N/A - Website Staff - '.retrieveNumVotes('c').' votes ('.makePercentage('c').')<br /></li>';
  91. ?>
  92. <br><h3>Judicial</h3>
  93. <?php
  94. $form = '<form action="" method="POST">
  95. <input type="radio" name="vote" value="1" /><li>N/A - Judge</li>
  96. <br />
  97. <input type="radio" name="vote" value="2" /><li>N/A - Forum Moderator</li>
  98. <br />
  99. <input type="radio" name="vote" value="3" /><li>N/A - Historian</li>
  100. <br />
  101. <input type="submit" name="submit" value="Vote" />
  102. </form>';
  103. $ip_address = $_SERVER['REMOTE_ADDR'];
  104. $checkIP = $mysqli->query("SELECT * FROM judicial WHERE ip_address='$ip_address'");
  105.  
  106. if (isset($_POST['submit'])) {
  107. $ip_address = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']);
  108.  
  109. if (!$result = $mysqli->query("SELECT * FROM judicial WHERE ip_address='$ip_address'")) {
  110. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  111. }
  112.  
  113. if ($result->num_rows == 0) {
  114. $vote = $mysqli->real_escape_string($_POST['vote']);
  115. if (!$mysqli->query("INSERT INTO judicial (vote, ip_address) VALUES ('$vote', '$ip_address')")) {
  116. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  117. } else {
  118. echo '<p>Success</p>';
  119. }
  120. }
  121. $result->close();
  122. }
  123.  
  124. if ($checkIP->num_rows == 0) {
  125. echo $form;
  126. } else {
  127. echo '<p>You have already voted</p>';
  128. }
  129.  
  130. echo '<li>N/A - Judge - '.retrieveNumVotes('1').' votes ('.makePercentage('1').')<br /></li>';
  131. echo '<li>N/A - Forum Moderator - '.retrieveNumVotes('2').' votes ('.makePercentage('2').')<br /></li>';
  132. echo '<li>N/A - Historian - '.retrieveNumVotes('3').' votes ('.makePercentage('3').')<br /></li>';
  133. ?>
  134. <br><h3>Executive</h3>
  135. <?php
  136. $form = '<form action="" method="POST">
  137. <input type="radio" name="vote" value="!" /><li>N/A - Leader</li>
  138. <br />
  139. <input type="radio" name="vote" value="@" /><li>N/A - War-Leader</li>
  140. <br />
  141. <input type="radio" name="vote" value="#" /><li>N/A - Co-Leader</li>
  142. <br />
  143. <input type="radio" name="vote" value="$" /><li>N/A - Tron</li>
  144. <br />
  145. <input type="submit" name="submit" value="Vote" />
  146. </form>';
  147. $ip_address = $_SERVER['REMOTE_ADDR'];
  148. $checkIP = $mysqli->query("SELECT * FROM executive WHERE ip_address='$ip_address'");
  149.  
  150. if (isset($_POST['submit'])) {
  151. $ip_address = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']);
  152.  
  153. if (!$result = $mysqli->query("SELECT * FROM executive WHERE ip_address='$ip_address'")) {
  154. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  155. }
  156.  
  157. if ($result->num_rows == 0) {
  158. $vote = $mysqli->real_escape_string($_POST['vote']);
  159. if (!$mysqli->query("INSERT INTO executive (vote, ip_address) VALUES ('$vote', '$ip_address')")) {
  160. echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
  161. } else {
  162. echo '<p>Success</p>';
  163. }
  164. }
  165. $result->close();
  166. }
  167.  
  168. if ($checkIP->num_rows == 0) {
  169. echo $form;
  170. } else {
  171. echo '<p>You have already voted</p>';
  172. }
  173.  
  174. echo '<li>N/A - Leader - '.retrieveNumVotes('!').' votes ('.makePercentage('!').')<br /></li>';
  175. echo '<li>N/A - War-Leader - '.retrieveNumVotes('@').' votes ('.makePercentage('@').')<br /></li>';
  176. echo '<li>N/A - Co-Leader - '.retrieveNumVotes('#').' votes ('.makePercentage('#').')<br /></li>';
  177. echo '<li>N/A - Tron - '.retrieveNumVotes('$').' votes ('.makePercentage('$').')<br /></li>';
  178. ?>
  179. </div>
  180. </div>
  181. <?php include("includes/rightside.html"); ?>
  182. </div>
  183. <div class="row">
  184. <div class="sixteen columns">
  185. <?php include("includes/footer.html"); ?>
  186. </div>
  187. </div>
  188. </div>
  189. </body>
  190. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement