1

我正在尝试在 Flash 中创建用户登录系统,但我需要通过 PHP 与 MySQL 通信才能这样做。我查看了一些教程,但我一直遇到错误。

这是我在 Flash 中制作的界面,我正在尝试与 controlpanel.php 进行通信

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

这是代码

文件

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
$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
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";    
}
?>

我没有收到任何错误,但是当我按下提交按钮时,结果文本框中显示未定义,即使我输入了正确的用户名和密码。

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

对于那些感兴趣的人:这是我的网站,请在此处输入链接描述

4

1 回答 1

1

所以问题最终出现在你SELECT * FROM user...应该是的时候SELECT * FROM users...=)

于 2012-12-11T22:36:33.693 回答