# Problem sending data from AS3 to PHP

**URL:** <https://forum.kirupa.com/t/problem-sending-data-from-as3-to-php/315437>\
**Category:** flash\
**Created:** [October 26, 2010, 6:21am UTC](https://forum.kirupa.com/t/problem-sending-data-from-as3-to-php/315437 "2010-10-26T06:21:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![leeda111](https://avatars.discourse-cdn.com/v4/letter/l/b9bd4f/32.png) [@leeda111](https://forum.kirupa.com/u/leeda111)\
**Post date:** [October 26, 2010, 6:21am UTC](https://forum.kirupa.com/t/problem-sending-data-from-as3-to-php/315437/1 "2010-10-26T06:21:46Z")

</div>

HI,

I am working to send data from as3 to php and I am having a little trouble with it. I am new to both AS3 and php but at this point I think I am doing fine.

The project is simple it just takes two values from as3 and send its to php. But apparently I am not able to send variables from as3 to php. Here is the code(its very simple code):

AS3 code:

```auto
  import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
	 import flash.net.*;	

btn_mc.addEventListener(MouseEvent.MOUSE_DOWN, onLogin);

function onLogin(e:MouseEvent):void {
 
   
   var username:String="aa1";
   var userpass:String="aa1";
   
   //string together a nice universal variable for php
   var variables:URLVariables = new URLVariables();
   variables.username = username;
   variables.userpass = userpass;
   trace("this is variables: " + variables);
 [COLOR="Red"] **//The output is:this is variables: username=aa1&userpass=aa1** [/COLOR]

   
   //Pass input variables to php...
   var phpReq:URLRequest = new URLRequest();
   phpReq.url = "http://localhost/Newfolder/insert.php";
   phpReq.method = URLRequestMethod.POST;
   phpReq.data = variables;
   trace("this is phpReq: " + phpReq.data);
  **[COLOR="DarkGreen"] //The output is:this is phpReq: username=aa1&userpass=aa1[/COLOR]**
   
   //load the php file and the results...
   var phpLoader:URLLoader = new URLLoader(phpReq);
   phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
   phpLoader.addEventListener(Event.COMPLETE, onPhpLoad);
   phpLoader.load(phpReq);

   function onPhpLoad(e:Event):void {
      var fromPhp:URLVariables = new URLVariables(e.target.data);
      trace(fromPhp);
	  trace(fromPhp.checking);
**[COLOR="Red"]//The output is:checking=ok&foo=bar[/COLOR]**

	  status.text = fromPhp.checking;
[COLOR="red"] **//status.text changed to OK** [/COLOR]
   }
}

```

insert.php

> \<?php  
> $username = $\_POST[‘username’];  
> $userpass = $\_POST[‘userpass’];

$con = mysql\_connect

(“localhost”,“root”,“123”);  
if (!$con)  
{  
die('Could not connect: ’ .

mysql\_error());  
}

mysql\_select\_db(“test”, $con);

mysql\_query("INSERT INTO users

(username, password, user\_bio)  
VALUES ($username, $userpass, ‘35’)");

echo “foo=bar&checking=ok”;

mysql\_close($con);  
?\>

I am sure the insert.php is working as I hardcoded the values in insert.php and it inserts the rows. So, I am assuming that there is some problem with sending the data from as3 to php. Any help will be really appreciated.

Thanks in advance
