Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Server credintails
- $servername = "GONE";
- $username = "GONE";
- $password = "GONE";
- $dbname = "GONE";
- // Connect to server
- $conn = new mysqli($servername, $username, $password, $dbname);
- $sql = "SELECT uid FROM tickets"; // Query
- $result = $conn->query($sql); // Get result of the query
- $count = 0; // Set count to 0
- $tickets = array(); // Make tickets a array
- while($row = $result->fetch_assoc()) { // For every result of the query
- $count++; // set count + 1
- $tickets[$count] = $row['uid']; // Put every ticket (with the user id) in a array
- }
- $total = count($tickets); // Count amount of tickers
- $winticket = rand(1, $total); // Choose the winning ticket
- $sql = "SELECT username, id, amount FROM users"; // Query
- $result = $conn->query($sql); // Get result of the query
- while($row = $result->fetch_assoc()) { // For every result of the query
- if ($row['id'] == $tickets[$winticket]) { // if user id = winning user id
- $winid = $row['id']; // Set the user id of the winner
- $winbal = $row['amount']; // Set the balance of the winner
- $winuser = $row['username']; // Set the username of the winner
- }
- }
- $payingout = $count*5; // Increment of how many tickets there are sold
- $newbal = $winbal + $payingout + 100; // Combine winner balance + jackpot money
- $sql = "UPDATE users SET amount='$newbal' WHERE id=".$winid; // Query to update winner balance
- $conn->query($sql); // Execute query
- $sql = "DELETE FROM tickets"; // Query to delete all tickets
- $conn->query($sql); // Execute query
- $file_handle = fopen("latest.txt", 'w'); // Open file
- fwrite($file_handle, $winuser); // Set winner username in a file
- fclose($file_handle); // Close file
- ?>
Add Comment
Please, Sign In to add comment