Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function SendData():void {
- var myData:URLVariables = new URLVariables();
- myData.update = "true";
- myData.score_humans = MasterManager.gameManager.scoreHumans;
- myData.score_creatures = MasterManager.gameManager.scoreCreatures;
- var myRequest:URLRequest = new URLRequest("http://not-a-real-web-server.com/data/testgame.php");
- myRequest.data = myData;
- myRequest.method = URLRequestMethod.POST;
- var loader:URLLoader = new URLLoader();
- loader.dataFormat = URLLoaderDataFormat.VARIABLES;
- loader.addEventListener(Event.COMPLETE, OnSendDataComplete);
- try {
- loader.load(myRequest);
- } catch (error:Error) {
- trace ('Error: unable to load the document.');
- }
- }
- public function OnSendDataComplete(e:Event):void {
- }
- <?php
- if (isset($_POST['update'])) {
- $dbhost = 'xxx.xxx.xxx.xxx';
- $dbuser = 'bogususer';
- $dbpass = 'boguspassword';
- $mysqli = new mysqli($dbhost, $dbuser, $dbpass, 'test_game_table', 3306);
- if ($mysqli->connect_errno) {
- echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
- }
- $score_humans = intval( $_POST['score_humans'] );
- $score_creatures = intval( $_POST['score_creatures'] );
- if ($score_humans >= 0 && $score_creatures >= 0) { // Error-check: No negative values
- $strquery = "update stats";
- $strquery .= " set score_humans = score_humans + " . $score_humans;
- $strquery .= ", score_creatures = score_creatures + " . score_creatures;
- $strquery .= " where id = 1";
- $strquery = $mysqli->real_escape_string($strquery); // Even though it should be clean, sanitize it anyways.
- $mysqli->query($strquery);
- echo "received=true";
- }
- }
- echo "Hello there!";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement