Hello,
Currently I’m setting up a webservice, which includes a login to access the member area. I’m testing all components seperately, and I’ve ran into a problem. When the user logs in I want flash to retrieve the user_id as a variable, so that I can use this user_id for member related database access. However, I’m having problems with retrieving the user_id.
The login is done by inputting the email and password of the user. If these variables match the data in the database the user is send to the member area. I want to get the user_id by posting the email variable to a php file. In the php file the following code is responsible for this:
$email = mysql_real_escape_string($_POST["email"]);
The mySQL query is as follows:
$query = "SELECT id FROM members
WHERE email = '$email'";
I send the variable back to flash through the following code:
$userID = mysql_query($query) or die("Data not found.");
echo "userID=$userID";
The actionscript code is as follows:
//post email and get user_id
getID_btn.addEventListener(MouseEvent.CLICK, sendEmail)
function sendEmail(event:Event){
var myData:URLRequest = new URLRequest("getID.php")
myData.method = URLRequestMethod.POST
var variables:URLVariables = new URLVariables()
variables.email = email_txt.text
myData.data = variables
var loader:URLLoader = new URLLoader()
loader.dataFormat = URLLoaderDataFormat.VARIABLES
loader.load(myData)
//get id
var idLoader:URLLoader = new URLLoader()
idLoader.dataFormat = URLLoaderDataFormat.VARIABLES
idLoader.load(new URLRequest("getID.php"))
idLoader.addEventListener(Event.COMPLETE, onDataLoad)
//add a listener for the complete event
function onDataLoad(event:Event){
id_txt.text = event.target.data.userID
}
}
When I run the file to test if I can get the user_id I get an actionscript error. Can anyone tell me what I’m doing wrong?
I posted the files under http://www.xs4all.nl/~karhen/Kirupa/
Thanks in advance!