Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysqli = new mysqli("localhost", "a3519_glenn", "Dontchoke1", "a3519_poll");
- if ($mysqli->connect_errno) {
- printf("Connect failed: %s\n", $mysqli->connect_error);
- exit();
- }
- function retrieveNumVotes($letter) {
- global $mysqli;
- if (!$result = $mysqli->query("SELECT * FROM legislative WHERE vote='$letter'")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- }
- $total = $result->num_rows;
- $result->close();
- return $total;
- }
- function makePercentage($letter) {
- global $mysqli;
- if (!$result = $mysqli->query("SELECT * FROM legislative")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- }
- $total_votes = $result->num_rows;
- $result->close();
- if ($total_votes == 0) return '0%';
- $percent = round((float)retrieveNumVotes($letter)/$total_votes * 100).'%';
- return $percent;
- }
- ?>
- <!DOCTYPE html>
- <!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
- <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
- <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
- <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
- <?php include("includes/head.html"); ?>
- <body>
- <div class="container">
- <a name="top"></a><?php include("includes/loginbar.html"); ?>
- <div class="row">
- <div class="sixteen columns">
- <div id="banner"></div>
- </div>
- </div>
- <?php include("includes/navbar.html"); ?>
- <div class="row">
- <?php include("includes/leftside.html"); ?>
- <div class="ten columns"><div id="center-block">
- <h4>Voting</h4>
- <h3>Legislative</h3>
- <?php
- $form = '<form action="" method="POST">
- <input type="radio" name="vote" value="a" /><li>N/A - Legislator</li>
- <br />
- <input type="radio" name="vote" value="b" /><li>N/A - Organizer</li>
- <br />
- <input type="radio" name="vote" value="c" /><li>N/A - Website Staff</li>
- <br />
- <input type="submit" name="submit" value="Vote" />
- </form>';
- $ip_address = $_SERVER['REMOTE_ADDR'];
- $checkIP = $mysqli->query("SELECT * FROM legislative WHERE ip_address='$ip_address'");
- if (isset($_POST['submit'])) {
- $ip_address = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']);
- if (!$result = $mysqli->query("SELECT * FROM legislative WHERE ip_address='$ip_address'")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- }
- if ($result->num_rows == 0) {
- $vote = $mysqli->real_escape_string($_POST['vote']);
- if (!$mysqli->query("INSERT INTO legislative (vote, ip_address) VALUES ('$vote', '$ip_address')")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- } else {
- echo '<p>Success</p>';
- }
- }
- $result->close();
- }
- if ($checkIP->num_rows == 0) {
- echo $form;
- } else {
- echo '<p>You have already voted</p>';
- }
- echo '<li>N/A - Legislator - '.retrieveNumVotes('a').' votes ('.makePercentage('a').')<br /></li>';
- echo '<li>N/A - Organizer - '.retrieveNumVotes('b').' votes ('.makePercentage('b').')<br /></li>';
- echo '<li>N/A - Website Staff - '.retrieveNumVotes('c').' votes ('.makePercentage('c').')<br /></li>';
- ?>
- <br><h3>Judicial</h3>
- <?php
- $form = '<form action="" method="POST">
- <input type="radio" name="vote" value="1" /><li>N/A - Judge</li>
- <br />
- <input type="radio" name="vote" value="2" /><li>N/A - Forum Moderator</li>
- <br />
- <input type="radio" name="vote" value="3" /><li>N/A - Historian</li>
- <br />
- <input type="submit" name="submit" value="Vote" />
- </form>';
- $ip_address = $_SERVER['REMOTE_ADDR'];
- $checkIP = $mysqli->query("SELECT * FROM judicial WHERE ip_address='$ip_address'");
- if (isset($_POST['submit'])) {
- $ip_address = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']);
- if (!$result = $mysqli->query("SELECT * FROM judicial WHERE ip_address='$ip_address'")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- }
- if ($result->num_rows == 0) {
- $vote = $mysqli->real_escape_string($_POST['vote']);
- if (!$mysqli->query("INSERT INTO judicial (vote, ip_address) VALUES ('$vote', '$ip_address')")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- } else {
- echo '<p>Success</p>';
- }
- }
- $result->close();
- }
- if ($checkIP->num_rows == 0) {
- echo $form;
- } else {
- echo '<p>You have already voted</p>';
- }
- echo '<li>N/A - Judge - '.retrieveNumVotes('1').' votes ('.makePercentage('1').')<br /></li>';
- echo '<li>N/A - Forum Moderator - '.retrieveNumVotes('2').' votes ('.makePercentage('2').')<br /></li>';
- echo '<li>N/A - Historian - '.retrieveNumVotes('3').' votes ('.makePercentage('3').')<br /></li>';
- ?>
- <br><h3>Executive</h3>
- <?php
- $form = '<form action="" method="POST">
- <input type="radio" name="vote" value="!" /><li>N/A - Leader</li>
- <br />
- <input type="radio" name="vote" value="@" /><li>N/A - War-Leader</li>
- <br />
- <input type="radio" name="vote" value="#" /><li>N/A - Co-Leader</li>
- <br />
- <input type="radio" name="vote" value="$" /><li>N/A - Tron</li>
- <br />
- <input type="submit" name="submit" value="Vote" />
- </form>';
- $ip_address = $_SERVER['REMOTE_ADDR'];
- $checkIP = $mysqli->query("SELECT * FROM executive WHERE ip_address='$ip_address'");
- if (isset($_POST['submit'])) {
- $ip_address = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']);
- if (!$result = $mysqli->query("SELECT * FROM executive WHERE ip_address='$ip_address'")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- }
- if ($result->num_rows == 0) {
- $vote = $mysqli->real_escape_string($_POST['vote']);
- if (!$mysqli->query("INSERT INTO executive (vote, ip_address) VALUES ('$vote', '$ip_address')")) {
- echo "ERROR: (" . $mysqli->errno . ") " . $mysqli->error;
- } else {
- echo '<p>Success</p>';
- }
- }
- $result->close();
- }
- if ($checkIP->num_rows == 0) {
- echo $form;
- } else {
- echo '<p>You have already voted</p>';
- }
- echo '<li>N/A - Leader - '.retrieveNumVotes('!').' votes ('.makePercentage('!').')<br /></li>';
- echo '<li>N/A - War-Leader - '.retrieveNumVotes('@').' votes ('.makePercentage('@').')<br /></li>';
- echo '<li>N/A - Co-Leader - '.retrieveNumVotes('#').' votes ('.makePercentage('#').')<br /></li>';
- echo '<li>N/A - Tron - '.retrieveNumVotes('$').' votes ('.makePercentage('$').')<br /></li>';
- ?>
- </div>
- </div>
- <?php include("includes/rightside.html"); ?>
- </div>
- <div class="row">
- <div class="sixteen columns">
- <?php include("includes/footer.html"); ?>
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement