Advertisement
Guest User

Untitled

a guest
Jun 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $servername = "localhost";
  5. $username = "myUser";
  6. $password = "myPass";
  7. $dbname = "myDBname";
  8. $cash_amount = $_SESSION['cash_amount'];
  9.  
  10. // Create connection
  11.  
  12. $userid = $_SESSION['id'];
  13.  
  14. // You must enter the user's id here. /
  15.  
  16. $conn = new mysqli($servername, $username, $password, $dbname);
  17. // Check connection
  18.  
  19. if ($conn->connect_error) {
  20. die("Connection failed: " . $conn->connect_error);
  21. }
  22.  
  23. // Fetch the existing value of the cash_amount against that particular user here. You can use the SELECT cash_amount from users where userid = $userid
  24. $_SESSION['cash_amount'] -= 0.05;
  25. $newAmount = $cash_amount - 0.05;
  26.  
  27. $sql = "UPDATE users SET cash_amount = $newAmount WHERE id = $userid";
  28. $result = $conn->query($sql);
  29.  
  30. if($result)
  31. {
  32. echo "5 cents have been subtracted!";
  33. }
  34. else
  35. {
  36. echo mysqli_error($conn);
  37. session_start();
  38. session_unset();
  39. session_destroy();
  40. }
  41.  
  42. $conn->close();
  43. ?>
  44.  
  45. function countdownEnded() {
  46. //make serverscreen dissapear
  47. document.getElementById('serverScreenWrapper').style.display = 'none';
  48. document.getElementById('serverScreenWrapper').style.opacity = '0';
  49. document.getElementById("cashOutNumTwo").style.right = '150%';
  50. document.getElementById("cashOutNumOne").style.right = '150%';
  51. //start Timer
  52. setInterval(gameTimer.update, 1000);
  53. //make player move again
  54. socket.emit('4');
  55. socket.emit('6');
  56. //make game appear
  57. document.getElementById('gameAreaWrapper').style.opacity = 1;
  58. //play sound
  59. document.getElementById('spawn_cell').play();
  60. //cut 5 cents from account - php function
  61. $.ajax({
  62. type: "POST",
  63. url: 'http://cashballz.net/game/5game/subtract5.php',
  64. data: { },
  65. success: function (data) {
  66. alert(data);
  67. }
  68. });
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement