Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connection details
- $servername = "";
- $user = "";
- $password = "";
- $dbname = "";
- // Your data variables, you can have as many as you want.
- $timetemp = $_GET ['time']; // The total time ran
- $killstemp = $_GET ['kills']; // The total kills
- $nametemp = $_GET ['name']; // The username of the botter.
- $profittemp = $_GET ['profit']; // The total profit made
- // Variable conn is used to determine the new mysql connection for above data
- // If you are running this script off the same webserver that the database is stored on, the servername can be NULL.
- $conn = mysqli_connect ($servername, $user, $password, $dbname );
- // Checking if the connection is valid, if not, killing the process and throwing a error message
- if ($conn->connect_error) {
- die ( "Connection failed: " . $conn->connect_error );
- }
- if (mysqli_connect_errno ()) {
- echo "Failed to connect to the mySQL server ";
- die ();
- }
- $setResult = mysqli_query ( $conn, "SELECT * FROM Data WHERE Username='$nametemp'" ); // Selects all fields from the Data table, based on the username supplied
- if ($setResult) {
- /*
- If the Table already contains some data for this user,
- it will instead ADD the new data onto the old data, then insert it back into the table.
- */
- $resultArray = mysqli_fetch_row($setResult);
- $time = $resultArray[1];
- $profit = $resultArray[2];
- $kills = $resultArray[3];
- $profit2 = $profit + $profittemp;
- $kills2 = $kills + $killstemp;
- $time2 = $time + $timetemp;
- // Query for inserting the wanted data into the mysql - Where Data is the table name
- $sql = "REPLACE INTO Data (Username, timeran, profit, kills)
- VALUES ('$nametemp', '$time2',' $profit2', '$kills2')";
- if (mysqli_query ( $conn, $sql )) {
- echo "Recorded Data";
- } else {
- echo "Error: " . $sql . "<br>" . mysqli_error ( $conn );
- }
- } else{ // If there is currently no user data, it will insert a fresh sample.
- $sql = "INSERT INTO Data (Username, timeran, profit, kills)
- VALUES ('$nametemp', '$timetemp',' $profittemp', '$killstemp')";
- if (mysqli_query ( $conn, $sql )) {
- echo "Recorded new Data";
- } else {
- echo "Error: " . $sql . "<br>" . mysqli_error ( $conn );
- }
- }
- $conn->close ();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement