Copy link to clipboard
Copied
Hello,
I'm trying to create the most basic example I can of an AS3/PHP/MySQL interaction. I want a Flash movie to check a user's login/pass against a DB. I've tested the PHP code and know it's correct. The problem must lie in the AS. I've traced everything to make sure it goes out correctly, but it comes back as the variable names $user, $pass...and some other garbage... not the variable values I am expecting... see below.
The PHP code correctly returns the following when tested in browser: user=dan&pass=danpass&err=Success!
The traced variables $user, $pass, $err return the following in Flash:
undefined
$pass
$err";
echo $returnString;
}
?>
Here's the ActionScript:
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
logbtn.addEventListener(MouseEvent.CLICK, login)
function login($e:MouseEvent){
var myVariables:URLVariables = new URLVariables();
var myRequest:URLRequest = new URLRequest("login.php");
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVariables;
var myLoader:URLLoader = new URLLoader;
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
myVariables.user = loguser.text;
myVariables.pass = logpass.text;
myLoader.load(myRequest);
function completeHandler(event:Event):void{
trace(event.target.data.user);
trace(event.target.data.pass);
trace(event.target.data.err);
}
}
And here's the PHP:
<?php
include_once "dbconnect.php";
$user = $_POST['user'];
$pass = $_POST['pass'];
$sql = mysql_query("SELECT * FROM users WHERE user = '$user' AND pass = '$pass'");
$check = mysql_num_rows($sql);
if($check > 0){
$row = mysql_fetch_array($sql);
$user = $row["user"];
$pass = $row["pass"];
$err = "Success!";
$returnString = "user=$user&pass=$pass&err=$err";
echo $returnString;
}
?>
Does anything stand out as being wrong? I've gone over this for probably 10-15 hours trying different variations, tweaks, and reducing it in complexity. I will really appreciate any help you can offer! Thank you.
-Eric
1 Correct answer
Hi,
are you loading the php from a file in the same folder, or from localhost (running the swf in a browser)?
If running from localhost, your system might deliver rather than execute php scripts
Copy link to clipboard
Copied
Hi,
are you loading the php from a file in the same folder, or from localhost (running the swf in a browser)?
If running from localhost, your system might deliver rather than execute php scripts
Copy link to clipboard
Copied
Thanks Birnerseff!
I've been running the SWF from the same directory as the PHP script. I just tried viewing it through my localhost and it worked! I guess I'll have to do all my testing that way, but that's fine.
Thank you very much. I probably wouldn't have messed around with that for a long time otherwise.
-Eric

