发送和从Flash AS3接收数据到PHP [英] Sending and receiving data from Flash AS3 to PHP

查看:120
本文介绍了发送和从Flash AS3接收数据到PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是常见的,但我期待所有在互联网上找到我正在与code,我用来发送和接收来自AS3数据到PHP,反之亦然错误。你能发现其中的错误?这是我的code:

I know this is frequently asked, but I have looked all over the internet to find the mistake I'm making with the code I've used to send and receive data from AS3 to PHP and viceversa. Can you find the mistake? Here is my code:

AS3:

import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;
import flash.events.Event;

submitbtn.addEventListener(MouseEvent.CLICK, sendData)

function sendData(event:MouseEvent):void
{
    var loader : URLLoader = new URLLoader;
    var urlreq:URLRequest = new URLRequest("http://[mydomain]/test.php");
    var urlvars: URLVariables = new URLVariables;
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    urlreq.method = URLRequestMethod.POST;
    urlvars.uname = nametxt.text;
    urlvars.apellido = aptxt.text;
    urlvars.email = emtxt.text;
    urlvars.cedula = cctxt.text;
    urlvars.score = scoretxt.text;
    urlreq.data = urlvars;
    loader.addEventListener(Event.COMPLETE, completed);
    loader.load(urlreq);
}

function completed(event:Event): void
{
    var loader2: URLLoader = URLLoader(event.target);
    trace(loader2.data.done);
    resptxt.text = event.target.data.done;
}

PHP [域] /test.php内:

<?php
    $username = $_POST["uname"];
    $apellido = $_POST["apellido"];
    $cedula = $_POST["cedula"];
    $email = $_POST["email"];
    $score = $_POST["score"];
    print_r($_POST);
    if (!($link=mysql_connect(databasemanager,username,password))) 
       { 
          echo "Error conectando a la base de datos."; 
          exit(); 
       } 
       if (!mysql_select_db(database,$link)) 
       { 
          echo "Error seleccionando la base de datos."; 
          exit(); 
       }
       try
       {
           mysql_query("insert into scores(name,lastName,email,document,score) values('$username','$apellido','$email','$cedula','$score')",$link);                
           print "done=true";          
       }
       catch(Exception $e)
       {
           print "done=$e->getMessage()";          
       }
       echo "done=true";    
?>

谢谢您的回答。

Thanks for your answers.

推荐答案

您AS code似乎是正确的。所以,问题可能是在PHP。请这个PHP文件中第一次测试:

Your AS code seems to be right. So the problem might be in PHP. Please test first with this PHP file:

<?php
       echo "test=1&done=true";    
?>

这应该然后让你的电影痕迹真实。 然后,您应该调试你的PHP。 的print_r($ _ POST); 破坏你的课程输出。可能是你没忘记删除这个调试声明: - )

This should then let your movie trace "true". You then should debug your PHP. print_r($_POST); destroys your output of course. May be you did forget to remove this debugging statement :-)

@Jesse和@​​Ascension系统,查看文档的使用URLVariables:<一href="http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/net/URLVariables.html">http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/net/URLVariables.html

@Jesse and @Ascension Systems, check the docs for URLVariables: http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/net/URLVariables.html

这篇关于发送和从Flash AS3接收数据到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆