简体   繁体   中英

Flash AS2 Store score in mysql database

i need to store variable score in database here's my code:

AS2 code:

    on(press)
{   var score = scorer.score

 var myDataResponse:LoadVars = new LoadVars();
 var myData:LoadVars = new LoadVars();
 score.sendAndLoad("score.php", myDataResponse, "POST");
 myDataResponse.onLoad = function() {
 if (this.result == "OK") {
 result= "Score Sent.";
 } else {
 result= this.result;
 }
 }

}

PHP code:

<?php
$score = $_POST['score'];
$con = mysql_connect("localhost","root","");
mysql_select_db("test",$con);


$q = ("INSERT INTO score(count) VALUES ('$score')");
mysql_query($q) or die ("error");
?>

i run .swf in localhost but didnt save the score

Change the AS3 code for onPress Method:

var loader : URLLoader = new URLLoader();  
var request : URLRequest = new URLRequest("/score.php");  

request.method = URLRequestMethod.POST;  
var variables : URLVariables = new URLVariables();  
variables.score = score;
request.data = variables;  

//  Handlers  
loader.addEventListener(Event.COMPLETE, on_complete);  
loader.load(request);  
private function on_complete(e : Event):void{  
       result= "Score Sent.";
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM