# AS3, MySQL, php: Post a variable, and retrieve info from db in flash

**URL:** https://forum.kirupa.com/t/as3-mysql-php-post-a-variable-and-retrieve-info-from-db-in-flash/293717
**Category:** flash
**Created:** [August 2, 2009, 1:14pm UTC](https://forum.kirupa.com/t/as3-mysql-php-post-a-variable-and-retrieve-info-from-db-in-flash/293717 "2009-08-02T13:14:06Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![goeiste](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/goeiste/32/2741_2.png) [@goeiste](https://forum.kirupa.com/u/goeiste)
#### Post date: [August 2, 2009, 1:14pm UTC](https://forum.kirupa.com/t/as3-mysql-php-post-a-variable-and-retrieve-info-from-db-in-flash/293717/1 "2009-08-02T13:14:06Z")

</div>

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:

```php
$email = mysql_real_escape_string($_POST["email"]);

```

The mySQL query is as follows:

```php
$query = "SELECT id FROM members
	WHERE email = '$email'";

```

I send the variable back to flash through the following code:

```php
$userID = mysql_query($query) or die("Data not found."); 
 
echo "userID=$userID";

```

The actionscript code is as follows:

```auto
//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/](http://www.xs4all.nl/~karhen/Kirupa/)

Thanks in advance!
