Advertisement
Guest User

Untitled

a guest
Mar 28th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2. // Connection details
  3. $servername = "";
  4. $user = "";
  5. $password = "";
  6. $dbname = "";
  7.  
  8. // Your data variables, you can have as many as you want.
  9. $timetemp = $_GET ['time']; // The total time ran
  10. $killstemp = $_GET ['kills']; // The total kills
  11. $nametemp = $_GET ['name']; // The username of the botter.
  12. $profittemp = $_GET ['profit']; // The total profit made
  13.  
  14.  
  15. // Variable conn is used to determine the new mysql connection for above data
  16.  
  17. // If you are running this script off the same webserver that the database is stored on, the servername can be NULL.
  18. $conn = mysqli_connect ($servername, $user, $password, $dbname );
  19.  
  20. // Checking if the connection is valid, if not, killing the process and throwing a error message
  21. if ($conn->connect_error) {
  22. die ( "Connection failed: " . $conn->connect_error );
  23. }
  24.  
  25. if (mysqli_connect_errno ()) {
  26. echo "Failed to connect to the mySQL server ";
  27. die ();
  28. }
  29.  
  30. $setResult = mysqli_query ( $conn, "SELECT * FROM Data WHERE Username='$nametemp'" ); // Selects all fields from the Data table, based on the username supplied
  31. if ($setResult) {
  32.  
  33. /*
  34. If the Table already contains some data for this user,
  35. it will instead ADD the new data onto the old data, then insert it back into the table.
  36. */
  37. $resultArray = mysqli_fetch_row($setResult);
  38. $time = $resultArray[1];
  39. $profit = $resultArray[2];
  40. $kills = $resultArray[3];
  41.  
  42.  
  43.  
  44. $profit2 = $profit + $profittemp;
  45. $kills2 = $kills + $killstemp;
  46. $time2 = $time + $timetemp;
  47.  
  48. // Query for inserting the wanted data into the mysql - Where Data is the table name
  49. $sql = "REPLACE INTO Data (Username, timeran, profit, kills)
  50. VALUES ('$nametemp', '$time2',' $profit2', '$kills2')";
  51.  
  52. if (mysqli_query ( $conn, $sql )) {
  53. echo "Recorded Data";
  54. } else {
  55. echo "Error: " . $sql . "<br>" . mysqli_error ( $conn );
  56. }
  57. } else{ // If there is currently no user data, it will insert a fresh sample.
  58. $sql = "INSERT INTO Data (Username, timeran, profit, kills)
  59. VALUES ('$nametemp', '$timetemp',' $profittemp', '$killstemp')";
  60.  
  61. if (mysqli_query ( $conn, $sql )) {
  62. echo "Recorded new Data";
  63. } else {
  64. echo "Error: " . $sql . "<br>" . mysqli_error ( $conn );
  65. }
  66. }
  67. $conn->close ();
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement