我正在使用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在浏览器中执行时会重新运行这些点,但不会连接到闪存。
<?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;
}
?>
非常感谢任何帮助!
答案 0 :(得分:1)
您必须在php中使用echo
或println
数据。
您必须打印的格式如下 -
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;
}
答案 1 :(得分:0)
尝试向PHP
,
$someVar = "l=l";
$someVar .= "&someData=".rawurlencode($someData);
echo $someVar;
祝你好运。