Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. public function SendData():void {
  2. var myData:URLVariables = new URLVariables();
  3.  
  4. myData.update = "true";
  5. myData.score_humans = MasterManager.gameManager.scoreHumans;
  6. myData.score_creatures = MasterManager.gameManager.scoreCreatures;
  7.  
  8. var myRequest:URLRequest = new URLRequest("http://not-a-real-web-server.com/data/testgame.php");
  9.  
  10. myRequest.data = myData;
  11. myRequest.method = URLRequestMethod.POST;
  12.  
  13. var loader:URLLoader = new URLLoader();
  14. loader.dataFormat = URLLoaderDataFormat.VARIABLES;
  15. loader.addEventListener(Event.COMPLETE, OnSendDataComplete);
  16.  
  17. try {
  18. loader.load(myRequest);
  19. } catch (error:Error) {
  20. trace ('Error: unable to load the document.');
  21. }
  22. }
  23.  
  24. public function OnSendDataComplete(e:Event):void {
  25. }
  26.  
  27. <?php
  28.  
  29. if (isset($_POST['update'])) {
  30. $dbhost = 'xxx.xxx.xxx.xxx';
  31. $dbuser = 'bogususer';
  32. $dbpass = 'boguspassword';
  33.  
  34. $mysqli = new mysqli($dbhost, $dbuser, $dbpass, 'test_game_table', 3306);
  35.  
  36. if ($mysqli->connect_errno) {
  37. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  38. }
  39.  
  40. $score_humans = intval( $_POST['score_humans'] );
  41. $score_creatures = intval( $_POST['score_creatures'] );
  42.  
  43. if ($score_humans >= 0 && $score_creatures >= 0) { // Error-check: No negative values
  44. $strquery = "update stats";
  45.  
  46. $strquery .= " set score_humans = score_humans + " . $score_humans;
  47. $strquery .= ", score_creatures = score_creatures + " . score_creatures;
  48.  
  49. $strquery .= " where id = 1";
  50.  
  51. $strquery = $mysqli->real_escape_string($strquery); // Even though it should be clean, sanitize it anyways.
  52.  
  53. $mysqli->query($strquery);
  54.  
  55. echo "received=true";
  56. }
  57. }
  58.  
  59. echo "Hello there!";
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement