0

I know this question has been asked before, but I've had little success even after visiting similar questions. I'm currently developing a Flash project which involves being able to create an account and log in. However, I keep getting "undefined" from my attempts to parse PHP output.

Here is my ActionScript 3.0 code for the function that contains the code.

function gosubmit(event:MouseEvent) {
    if (username.text != "" && password.text != "") {
        var phpVars:URLVariables = new URLVariables();
        var phpFileRequest:URLRequest = new URLRequest();
        phpFileRequest.url = "php/controlpanel.php";
        phpFileRequest.method = URLRequestMethod.POST;
        phpFileRequest.data = phpVars;

        var phpLoader:URLLoader = new URLLoader();
        phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
        phpLoader.addEventListener(Event.COMPLETE, execResult);

        phpVars.username = username.text;
        phpVars.password = password.text;

        phpLoader.load(phpFileRequest);
        phpLoader.addEventListener(Event.COMPLETE, execResult);

        function execResult(event:Event) {
            trace(event.target.data.execResult);
        }
    }

Here is the PHP code in php/controlpanel.php.

<?php

mysql_connect("localhost", "root", "password");
// change localhost to something else later
// change password to something else later
mysql_select_db("game");

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$salt_mysql = mysql_query("SELECT salt FROM players WHERE username='".$username."'"); 
$salt = salt_row["salt"];    

$unhashed_password = $password.$salt;
$password = hash("SHA256", $unhashed_password); 

$exec_mysql = mysql_query("SELECT * FROM players WHERE username='".$username."' AND password='".$password."'");

if (mysql_num_rows($exec_mysql)) == 1 {
    echo "execResult=login_accepted";
}

if (mysql_num_rows($exec_mysql)) == 0 {
    echo "execResult=login_rejected";
}

else {
    echo "execResult=error";
}

?>

I have compared my code with multiple sources, even copied whole projects from sources trying to figure out what I have done wrong, but with little success. However, there is something weird I found out. Out of pure experimentation, I put the following into controlpanel.php:

=&execResult=test

And, instead of getting "undefined", I got "test". The weird part is that I only used that one line of code; no <?php tags or anything. Moreover, if I put more code beyond that, regardless of what kind of code I entered, it would always show up literally in the Flash output. So I can now hardcode a value and return it into Flash, but that's not what I need. I need to be able to determine a value based on conditionals and have it automatically returned into Flash.

Can anyone help me out? I am truly stumped.

Thanks :)

3
  • Thank you for catching those! I appreciate it :) However, the PHP syntax errors don't seem to be causing the problem... Commented Sep 27, 2012 at 4:01
  • I changed the PHP code to <?php print "execResult=test"; ?>, but I still get "undefined". Is there still a syntax error in my code? Commented Sep 27, 2012 at 4:15
  • I get %3C%3Fphp%20print%20%22execResult=test%22%3B%20%3F%3E%0D%0A. I'm assuming that the non-alphanumeric characters are being translated into the %XY things. So now, I can put text into the Flash output manually, but I still don't see how I can use this to give a value automatically based on certain conditions. Commented Sep 27, 2012 at 4:43

1 Answer 1

2

Seems that you are executing flash from the editor/debugger, (if you are checking the results with trace function).

Then using a relative url for request "php/controlpanel.php" is like opening the file localy without the execution from server of php directives.

Maybe thats why you get literaly all php code, or the correct value when you only put "=&execResult=test" as the content of the php file.

Try using absolute url with the http:// in order to perform an http request where server and php execution are involved.

Sign up to request clarification or add additional context in comments.

1 Comment

I could have sworn I tried this before and it didn't work. I suppose that was a fault on my end...it seems to work. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.