Advertisement
tok124

Vote System

Apr 18th, 2015
231
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. include('../config/db_conf.php');
  4. $conn = mysqli_connect($host, $dbuser, $dbpass, $dbname);
  5. $site = $_POST['site'];
  6.  
  7. $selectsite = "SELECT points, id FROM vote_sites WHERE id = '$site'";
  8. $result = $conn->query($selectsite);
  9.  
  10. if ($result->num_rows > 0) {
  11.     while($row = $result->fetch_assoc()) {
  12.     $vp = $row['points'];
  13.     $siteid = $row['id'];
  14.     }
  15. }else{
  16.  
  17. }
  18.  
  19. $userip = $_SERVER['REMOTE_ADDR'];
  20.  
  21. if(isset($_SESSION['username'])) {
  22. $select = "SELECT vote_time FROM vote_cooldown WHERE user_ip = '$userip' AND siteid='$siteid'";
  23. $result = mysqli_query($conn, $select);
  24. if (mysqli_num_rows($result) > 0) {
  25.     while($row = mysqli_fetch_assoc($result)) {
  26.    
  27.         $votetime = $row['vote_time'];
  28.         $time = time();
  29.        
  30.         if($time >= $votetime+43200) {
  31.             $update = "UPDATE vote_cooldown SET vote_time='$time' WHERE user_ip = '$userip'";
  32.             if (mysqli_query($conn, $update)) {
  33.                 echo "successfully added new time<br>";
  34.             }else{
  35.                 echo "Failed to add new time" . mysqli_error($conn);
  36.             }
  37.             $updatevp = "UPDATE auth.account SET vp=vp+$vp WHERE username='" . $_SESSION['username'] . "'";
  38.             if (mysqli_query($conn, $updatevp)) {
  39.                 echo "Successfully added vp to account " . $_SESSION['username'] . "";
  40.             }else{
  41.                 echo "Failed to add vp to account " . $_SESSION['username'] . "";
  42.             }
  43.         }else{
  44.             echo "You have already voted !";
  45.         }
  46.        
  47.     }
  48.    
  49. }else{
  50.     $inserttime = time();
  51.     $insert = "INSERT INTO vote_cooldown (voted, account, user_ip, siteid, vote_time)
  52.     VALUES('1', '" . $_SESSION['username'] . "', '$userip', '$siteid', '$inserttime')";
  53.     if (mysqli_query($conn, $insert)) {}else{}
  54.     $newupdate = "UPDATE auth.account SET vp=vp+$vp WHERE username='" . $_SESSION['username'] . "'";
  55.     if (mysqli_query($conn, $newupdate)) {
  56.         echo "successfully added new time<br>";
  57.     }else{
  58.         echo "Failed to add new time" . mysqli_error($conn);
  59.     }
  60. }
  61. }else{
  62.     echo "You need to login to be able to vote !";
  63. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement