0

我使用 as3、mysql 和 php,尝试发送用户名并接收(积分)并将积分发布在舞台上的文本对象中,我可以使用类似的脚本将积分发送到服务器,但可以取回数字!


// global variables
var loader:URLLoader;
var urlReq:URLRequest;
var urlVars:URLVariables;
var myVars:URLVariables;


addEventListener(Event.ENTER_FRAME, onit);

function onit(e:Event):void
{


    urlReq = new URLRequest("http://www.mysite.com/GetPoints.php");
    urlReq.method = URLRequestMethod.POST;


    urlVars = new URLVariables();
    urlReq.data = urlVars;
    urlVars.username = nickname_txt.text;



    loader = new URLLoader(urlReq);
    loader.addEventListener(Event.COMPLETE, onUpdateComplete);


    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.load(urlReq);
}

function onUpdateComplete(e:Event):void
{
    myVars = e.target.data;
    totalP.text = myVars.total;
}

php 在浏览器中执行时重新运行这些点,但未连接到 flash。

<?php
$username = $_POST["username"];
    // defining main variables
    $dbHost = "localhost";
    $dbUser = "";
    $dbPass = "";
    $dbName = "";
    $dbTable = "`".$username."_points`";


    @mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
    @mysql_select_db($dbName) or die(mysql_error());


    $data = "";
    $res = mysql_query("SELECT * FROM ".$dbTable." ORDER BY id") or die(mysql_error());
    while($row = mysql_fetch_object($res)) {


        $data = "total=".$row->total;
        print $data;
    }

?>

任何帮助将不胜感激 !

4

2 回答 2

1

你必须echoprintln你的数据在 php.ini 中。

您必须打印的格式如下 -

key1=value1&key2=value2&key3=value3 and so on

然后你应该能够像这样访问 AS3 中的数据 -

myVars = e.target.data;
totalP.text = myVars.key1; //this will be value1

此外,您传递的第一个变量之前不应有 & 符号。

我建议你做的是这样的

print "key1=value1"; //print out a test value    
while($row = mysql_fetch_object($res)) {


        $data = "&total=".$row->total; //add an ampersand before the key
        print $data;
    }
于 2013-04-05T06:39:20.670 回答
0

尝试将这样的内容添加到您的PHP,

 $someVar  = "l=l";
 $someVar .= "&someData=".rawurlencode($someData);
 echo $someVar;

好运。

于 2013-04-05T08:23:38.003 回答