Guest User

php help

a guest
Jun 21st, 2017
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "aspire";
  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. $stmt->bind_param("ss", $account, $ip);
  29. $stmt->execute();
  30.  
  31.  
  32. $lasttime = mysql_fetch_array($stmt);
  33. $amount = $lasttime['amount'];
  34. $insertnew = false;
  35. if ($amount == "") {
  36. $insertnew = true;
  37. }
  38. $timecalc = $time - $lasttime['date'];
  39. if (!$insertnew) {
  40. if ($timecalc < 21600) {
  41. echo ' Hello '. $account .' you have already voted with this account ('. $account .') or IP ('. $ip .') in the last 6 hours!';
  42. echo ' Last voted on: '. date('M d\, h:i:s A', $lasttime['date']) .'';
  43. echo '<html>';
  44. echo '<head>';
  45. echo '<meta HTTP-EQUIV="REFRESH" content="3; url=http://www.">';
  46. echo '</head>';
  47. echo '<body>';
  48. echo '<br><br>You will be redirected to the main website in 3 seconds.';
  49. echo '</body>';
  50. echo '</html>';
  51. exit();
  52. } else {
  53. $update = $mysqli->prepare("UPDATE votingrecords SET account='$account', date='$time', times=times+1 WHERE ip='$ip'");
  54. $stmt->bind_param("sss", $account, $time, $ip);
  55. $stmt->execute();
  56. if (!$update) {
  57. $message = 'Invalid query: ' . mysql_error() . "\n";
  58. $message .= 'Whole query: ' . $update;
  59. die($message);
  60. } else {
  61. $earnedpoints = true;
  62. }
  63. }
  64. } else {
  65. $success = $mysqli->prepare("INSERT INTO votingrecords (`account`, `ip`, `date`, `times`) VALUES ('$account', '$ip', '$time', 1)");
  66. $stmt->bind_param("sss", $account, $ip, $time);
  67. $stmt->execute();
  68. if (!$success) {
  69. $message = 'Invalid query: ' . mysql_error() . "\n";
  70. $message .= 'Whole query: ' . $success;
  71. die($message);
  72. } else {
  73. $earnedpoints = true;
  74. }
  75. }
  76.  
  77.  
  78.  
  79.  
  80. if ($earnedpoints) {
  81. $points = $mysqli->prepare("UPDATE accounts SET votepoints = votepoints + 2 WHERE name='$account'");
  82. $stmt->bind_param("s", $account);
  83. $stmt->execute();
  84. if (!$points) {
  85.  
  86. $message = 'Invalid query: ' . mysql_error() . "\n";
  87. $message .= 'Whole query: ' . $stmt;
  88. die($message);
  89. }
  90. $stmt->close();
  91. echo '<html>';
  92. echo '<head>';
  93. echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.gtop100.com">';
  94. echo '</head>';
  95. echo '</html>';
  96. } else {
  97. echo 'There was an error processing your request.';
  98. exit();
  99. }
  100. ?>
Add Comment
Please, Sign In to add comment