Advertisement
Guest User

PHP help

a guest
Jun 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "username";
  5. $password = "password";
  6. $dbname = "myDB";
  7.  
  8.    
  9. $mysqli = new mysqli($servername, $username, $password, $dbname);
  10.  
  11. if ($mysqli->connect_error) {
  12.     die("Connection failed: " . $mysqli->connect_error);
  13. }
  14.  
  15. $earnedpoints = false;
  16. $account = $_POST['name'];
  17. $account = mysql_real_escape_string($account);
  18.  
  19. if ($account == "") {
  20.     echo 'Enter an account name!';
  21.     exit();
  22. }
  23.  
  24. $ip = $_SERVER['REMOTE_ADDR'];
  25. $time = time();
  26.  
  27. $stmt = $mysqli->prepare("SELECT *, SUM(`times`) as amount FROM votingrecords WHERE account='$account' OR ip='$ip'");
  28. $lasttime = mysql_fetch_array($stmt);
  29. $amount = $lasttime['amount'];
  30. $insertnew = false;    
  31. if ($amount == "") {
  32.     $insertnew = true;
  33. }
  34. $timecalc = $time - $lasttime['date'];
  35. if (!$insertnew) {
  36.     if ($timecalc < 21600) {  
  37.         echo ' Hello '. $account .' you have already voted with this account ('. $account .') or IP ('. $ip .') in the last 6 hours!';
  38.         echo ' Last voted on: '. date('M d\, h:i:s A', $lasttime['date']) .'';
  39.         echo '<html>';
  40.         echo '<head>';
  41.         echo '<meta HTTP-EQUIV="REFRESH" content="10; url=http://www.">';
  42.         echo '</head>';
  43.         echo '<body>';
  44.         echo '<br><br>You will be redirected to the main website in 10 seconds.';
  45.         echo '</body>';
  46.         echo '</html>';
  47.         exit();
  48.     } else {                
  49.         $update = $mysqli->prepare("UPDATE votingrecords SET account='$account', date='$time', times=times+1 WHERE ip='$ip'");
  50.             if (!$update) {
  51.                 $message  = 'Invalid query: ' . mysql_error() . "\n";
  52.                 $message .= 'Whole query: ' . $update;
  53.                 die($message);
  54.             } else {
  55.                 $earnedpoints = true;
  56.             }
  57.         }
  58. } else {
  59.     $success = $mysqli->prepare("INSERT INTO votingrecords (`account`, `ip`, `date`, `times`) VALUES ('$account', '$ip', '$time', 1)");
  60.     if (!$success) {
  61.             $message  = 'Invalid query: ' . mysql_error() . "\n";
  62.             $message .= 'Whole query: ' . $success;
  63.             die($message);
  64.     } else {
  65.         $earnedpoints = true;
  66.     }
  67. }
  68.  
  69.  
  70.  
  71.  
  72. if ($earnedpoints) {
  73.     $points = $mysqli->prepare("UPDATE accounts SET votepoints = votepoints + 2 WHERE name='$account'");                
  74.     if (!$points) {
  75.  
  76.             $message  = 'Invalid query: ' . mysql_error() . "\n";
  77.             $message .= 'Whole query: ' . $stmt;
  78.             die($message);
  79.     }
  80.     $stmt->execute();
  81.     $stmt->close();
  82.     echo '<html>';
  83.     echo '<head>';
  84.     echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.gtop100.com/">';
  85.     echo '</head>';
  86.     echo '</html>';
  87. } else {
  88.     echo 'There was an error processing your request.';
  89.     exit();
  90. }
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement