我有一个动作游戏,通过POST将数据发送到php。 但我不知道如何使其工作,首先在php中获取数据然后插入数据库。
这是ActionScript,游戏的一部分,将帖子发送给php。
public function post()
{
var _loc_1:* = new ByteArray();
_loc_1.writeUnsignedInt(1);
_loc_1.writeUnsignedInt(this.Args.u);
_loc_1.writeUnsignedInt(this.Args.r);
_loc_1.writeUnsignedInt(this.Args.t);
_loc_1.writeUnsignedInt(this.Args.p);
_loc_1.writeUnsignedInt(this.apples);
_loc_1.writeUnsignedInt(this.calories);
_loc_1.writeUnsignedInt(this.StartTime);
var _loc_2:* = 0;
while (_loc_2 < this.moves.length)
{
_loc_1.writeShort(this.moves[_loc_2]);
_loc_2 = _loc_2 + 1;
}
var _loc_3:* = new URLRequestHeader("Content-type", "application/octet-stream");
var _loc_4:* = new URLRequest("http://mywebsite.com/Game.php");
_loc_4.requestHeaders.push(_loc_3);
_loc_4.method = URLRequestMethod.POST;
_loc_4.data = _loc_1;
var _loc_5:* = new URLLoader();
_loc_5.load(_loc_4);
_loc_5.addEventListener(Event.COMPLETE, this.PostCallback);
return;
}// end function
public function PostCallback(param1)
{
this.tf.text = "PHP:" + param1.currentTarget.data;
return;
}// end function
某处是this.post();(在游戏结束时使用并获胜)
这是我想在php中得到的数据,就像得分:
var _loc_1:* = new ByteArray();
_loc_1.writeUnsignedInt(1);
_loc_1.writeUnsignedInt(this.Args.u);
_loc_1.writeUnsignedInt(this.Args.r);
_loc_1.writeUnsignedInt(this.Args.t);
_loc_1.writeUnsignedInt(this.Args.p);
_loc_1.writeUnsignedInt(this.apples);
_loc_1.writeUnsignedInt(this.calories);
_loc_1.writeUnsignedInt(this.StartTime);
Page Game.php
<?php
$dbhost = 'localhost';
$dbname = 'dbname';
$dbuser = 'root';
$dbbg = 'pass';
mysql_connect($dbhost, $dbuser, $dbbg)or error("Could not connect: ".mysql_error());
mysql_select_db($dbname) or error(mysql_error());
if(isset($HTTP_RAW_POST_DATA))
{
mysql_query("INSERT INTO game (gameinfo) VALUES ('".$HTTP_RAW_POST_DATA."');");
}
?>
它在数据库中插入了一个像废话人物一样的文字..'YPDèU“†U”~μIk€†««¹ãV“ - '
我很感激任何帮助。