本文介绍了什么是不对的AS3 code与PHP文件进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Flash中创建一个用户登录系统,但我需要通过PHP才能这样做的时候到MySQL。我看了看周围的一些教程,但我一直得到错误。

I am trying to create a user log-in system in Flash but I need to communicate to MySQL through PHP in order to do so. I looked around at a few tutorials, but I have been getting errors.

下面是我在Flash制作的界面,我试图用controlpanel.php沟通

Here is the interface I have made in flash, which I am trying to communicate with controlpanel.php

http://i.imgur.com/JrTWm.png?1

下面是code

AS文件

package actions
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import flash.net.URLVariables;
    import flash.net.URLLoader;
    import flash.events.Event;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequestMethod;
    import flash.text.TextFieldAutoSize;

    public class main extends MovieClip
    {
        public function main():void
        {
            submit_button.buttonMode = true;
            submit_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin)

            username.text = "";
            password.text = "";
        }

        public function checkLogin(e:MouseEvent):void
        {
            if(username.text==""||password.text=="")
            {
                if (username.text == "")
                {
                    username.text = "Enter your username";
                }

                if (password.text == "")
                {
                    password.text="Enter your password";
                }
            }
            else
            {
                processLogin();
            }
        }

        public function processLogin():void
        {
            var phpVars:URLVariables = new URLVariables();
            var phpFileRequest:URLRequest = new URLRequest("http://mathlympics.cu.cc/php/controlpanel.php");
            phpFileRequest.method = URLRequestMethod.POST;
            phpFileRequest.data = phpVars;

            var phpLoader:URLLoader=new URLLoader();
            phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

            phpVars.systemCall = "checkLogin";
            phpVars.username = username.text;
            phpVars.password = password.text;

            phpLoader.load(phpFileRequest);
            phpLoader.addEventListener(Event.COMPLETE, showResult);
        }

        public function showResult(event:Event):void
        {
            result_text.autoSize = TextFieldAutoSize.LEFT;
            result_text.text = ""+ event.target.data.systemResult;
        }
    }
}

PHP文件 - 将connect.php

PHP file - connect.php

<?php
$db_username = "censored";
$db_name = "censored";
$db_password = "censored";
$db_host = "mysql2.000webhost.com";
mysql_connect($db_host,$db_username, $db_password, $db_name);
mysql_select_db($db_name) or die (mysql_error());
?>

PHP文件 - controlpanel.php

PHP file - controlpanel.php

   <?php
error_reporting(E_ALL);
include_once("connect.php");
$username       = "admin";
$password       = "password";
$sql            = "SELECT * FROM user WHERE username='$username' AND password='$password'";
$query          = mysql_query($sql);
$login_counter  = mysql_num_rows($query);
if ($login_counter > 0)
{
    $data       = mysql_fetch_array($query);
    $userbio    = $data["user_bio"];
    echo "systemResult=" . $userbio;
}
else
{
    echo "systemResult=Invalid";
}
?>

我没有得到任何错误,但是当我preSS提交按钮,是说不确定的结果文本框中,即使当我输入正确的用户名和密码。

I do not get any error but when I press the submit button, is says undefined in the result text box, even when I type the right username and password.

<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

为那些你感兴趣的是:这是我的网站这里输入链接的描述

To those of you interested: Here is my website enter link description here

推荐答案

所以,问题最终被你有 SELECT * FROM用户... 时,它应该是 SELECT * FROM用户... =)

So the problem ended up being you had SELECT * FROM user... when it should have been SELECT * FROM users... =)

这篇关于什么是不对的AS3 code与PHP文件进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:20