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 :)
<?php print "execResult=test"; ?>, but I still get "undefined". Is there still a syntax error in my code?%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.