Advertisement
tok124

votefunction.php

Apr 17th, 2015
328
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. $vp = "10";
  6. if(isset($_SESSION['username'])) {
  7. $select = "SELECT vote_time FROM vote_cooldown WHERE account = '" . $_SESSION['username'] . "'";
  8. $result = mysqli_query($conn, $select);
  9. if (mysqli_num_rows($result) > 0) {
  10.     //Function to add if a row exist
  11.     while($row = mysqli_fetch_assoc($result)) {
  12.    
  13.         $votetime = $row['vote_time']; 
  14.         $time = time();
  15.        
  16.         if($time >= $votetime+43200) {
  17.             $update = "UPDATE vote_cooldown SET vote_time='$time' WHERE account='" . $_SESSION['username'] . "'";
  18.             if (mysqli_query($conn, $update)) {
  19.                 echo "successfully added new time<br>";
  20.             }else{
  21.                 echo "Failed to add new time" . mysqli_error($conn);
  22.             }
  23.             $updatevp = "UPDATE auth.account SET vp=vp+$vp WHERE username='" . $_SESSION['username'] . "'";
  24.             if (mysqli_query($conn, $updatevp)) {
  25.                 echo "Successfully added vp to account " . $_SESSION['username'] . "";
  26.             }else{
  27.                 echo "Failed to add vp to account " . $_SESSION['username'] . "";
  28.             }
  29.         }else{
  30.             echo "You have already voted !";
  31.         }
  32.        
  33.     }
  34.    
  35. }else{
  36.     $inserttime = time();
  37.     $insert = "INSERT INTO vote_cooldown (voted, account, vote_time)
  38.     VALUES('1', '" . $_SESSION['username'] . "', '$inserttime')";
  39.     if (mysqli_query($conn, $insert)) {}else{}
  40.     $newupdate = "UPDATE auth.account SET vp=vp+$vp WHERE username='" . $_SESSION['username'] . "'";
  41.     if (mysqli_query($conn, $newupdate)) {
  42.         echo "successfully added new time<br>";
  43.     }else{
  44.         echo "Failed to add new time" . mysqli_error($conn);
  45.     }
  46. }
  47. }else{
  48.     echo "You need to login to be able to vote !";
  49. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement