Guest User

Untitled

a guest
Dec 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. // Server credintails
  3. $servername = "GONE";
  4. $username = "GONE";
  5. $password = "GONE";
  6. $dbname = "GONE";
  7.  
  8. // Connect to server
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10.  
  11. $sql = "SELECT uid FROM tickets"; // Query
  12. $result = $conn->query($sql); // Get result of the query
  13. $count = 0; // Set count to 0
  14. $tickets = array(); // Make tickets a array
  15. while($row = $result->fetch_assoc()) { // For every result of the query
  16. $count++; // set count + 1
  17. $tickets[$count] = $row['uid']; // Put every ticket (with the user id) in a array
  18. }
  19. $total = count($tickets); // Count amount of tickers
  20. $winticket = rand(1, $total); // Choose the winning ticket
  21. $sql = "SELECT username, id, amount FROM users"; // Query
  22. $result = $conn->query($sql); // Get result of the query
  23. while($row = $result->fetch_assoc()) { // For every result of the query
  24. if ($row['id'] == $tickets[$winticket]) { // if user id = winning user id
  25. $winid = $row['id']; // Set the user id of the winner
  26. $winbal = $row['amount']; // Set the balance of the winner
  27. $winuser = $row['username']; // Set the username of the winner
  28. }
  29. }
  30. $payingout = $count*5; // Increment of how many tickets there are sold
  31. $newbal = $winbal + $payingout + 100; // Combine winner balance + jackpot money
  32. $sql = "UPDATE users SET amount='$newbal' WHERE id=".$winid; // Query to update winner balance
  33. $conn->query($sql); // Execute query
  34. $sql = "DELETE FROM tickets"; // Query to delete all tickets
  35. $conn->query($sql); // Execute query
  36. $file_handle = fopen("latest.txt", 'w'); // Open file
  37. fwrite($file_handle, $winuser); // Set winner username in a file
  38. fclose($file_handle); // Close file
  39. ?>
Add Comment
Please, Sign In to add comment