as3.0 login with php and mysql

Hello everyone,

Currently I’m trying to make a login with flash. Using actiosncript 3.0 I’m able to connected to a single php with stored info on it. Everything works fine just between php and as3.0. Then I try to connect it to the database (instead of static info in the php file) and it breaks. I ran some tests and was able to connect to the database with php and print the same strings as the static php file…yet the static php file works and the one connecting to the db does not (but they print the same exact responses wtf). Any help would be great because I’m lost.

Not working php code:


<?php

$n=$_POST['usernameStr'];
$p=$_POST['passwordStr'];

$hostname='localhost';
$username= 'x';
$password= 'x';
$conn = mysql_connect($hostname, $username, $password, 'test')
    or die ('Cannot open database');    
//database login (end) working


if(!empty($_POST)){
$query= "SELECT * FROM test.user WHERE uname='$n' and pw='$p'";
$result=mysql_query($query);
$count = mysql_num_rows($result);

    if($count==1) {
        print "resultCode=LOGGED_IN";
    }
    else
    {
        print "resultCode=NOT_LOGGED_IN";
    }
    }

?>

ps. I know security isn’t there but I’m just trying to connect at the moment I’ll deal with the other stuff later. Also here is the static working php file.

<?php

error_reporting(0); // disable all error reporting

$user = $_POST['usernameStr'];
$pass = $_POST['passwordStr'];

$storedPassword = "1cb251ec0d568de6a929b520c4aed8d1";

// At least some POST data is required

if(!empty($_POST))
{
    if($user == "guest" && md5($pass) == $storedPassword)
    {
        print "resultCode=LOGGED_IN";
    }
    else
    {
        print "resultCode=NOT_LOGGED_IN";
    }
}

?>

Lastly I will also include my as3.0:

var phpFile:String = “http://localhost/risingArtistry/blog2.php”;
var loggedIn:Boolean = false;

function loginClick (e:MouseEvent):void{
var usernameStr:String = usernameTxt.text;
var passwordStr:String = passwordTxt.text;

var allFields:Boolean = true;

if(usernameStr.length &lt; 1)
    { allFields = false; }
if (passwordStr.length &lt; 1)
    { allFields = false; }

if (!allFields)
    {addChild(error1Msg);
    error1Msg.x = 400;
    error1Msg.y = 300;
    addChild(closeBtn1);
    error1Msg.statusTxt.text = "please enter your username and password";
    closeBtn1.x = 540;
    closeBtn1.y = 215;
    }

var variables:URLVariables = new URLVariables();
variables.usernameStr = usernameStr;
variables.passwordStr = passwordStr;

var urlRequest:URLRequest = new URLRequest(phpFile);
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, sendHandler);
loader.load(urlRequest);

}

function sendHandler(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
var variables:URLVariables = new URLVariables(loader.data);

if(variables.resultCode == "LOGGED_IN")
{
    // message sent
    loggedIn = true;
    //form.statusTxt.htmlText = "&lt;font color=\"#009933\"&gt;Logged in!&lt;/font&gt;";
    gotoAndStop("secret_page");
}
else if(variables.resultCode == "NOT_LOGGED_IN")
{
    // message not sent
    addChild(error1Msg);
    error1Msg.x = 400;
    error1Msg.y = 300;
    addChild(closeBtn1);
    error1Msg.statusTxt.text = "The Username/Password you entered was incorrect";
    closeBtn1.x = 540;
    closeBtn1.y = 215;
}
else
{
    // unknown response
    error1Msg.statusTxt.htmlText = "&lt;font color=\"#FF0000\"&gt;Unknown ERROR&lt;/font&gt;";
}

}

//php info (end)//

stop();

If anyone has any suggestions please let me know. This is first time I’ve tried connecting to a database with flash. Also if anyone knows a good place to go to get info on this type of stuff that would be awesome…I could only find a few books on this and no tutorials.