Decode variables from PHP

Hi,

Been searching around to find a solution with no luck. I do hope someone can help here, or point me to a solution. This is all very new…

I’ve got a simple page in Flash that takes user info from three input boxes, sends the variables via PHP to mySQL, returns an auto-incremented ID from mySQL back to flash, which can be displayed on the page.

Here’s the AS3 code:

stop();

var SubID;

var subDetailsVars:URLVariables = new URLVariables();
var subDetailsURLRequest:URLRequest = new URLRequest("http://EDITED OUT!.php");
var subDetailsSender:URLLoader = new URLLoader();

subDetailsSender.addEventListener(Event.COMPLETE, loadSubDetailsSuccess);
subDetailsSender.addEventListener(IOErrorEvent.IO_ERROR, loadSubDetailsError);

btn1_btn.addEventListener(MouseEvent.CLICK, sendSubData);

function sendSubData(event:MouseEvent):void
{
    subDetailsVars.Name = inpName_txt.text;
    subDetailsVars.Age = inpAge_txt.text;
    subDetailsVars.Gender = inpGender_txt.text;
    
    subDetailsURLRequest.data = subDetailsVars;
    subDetailsURLRequest.method = URLRequestMethod.POST;
    //navigateToURL(subDetailsURLRequest, '_blank');
    subDetailsSender.load(subDetailsURLRequest);
}

function loadSubDetailsSuccess(event:Event):void
{    
    SubID = (event.target as URLLoader).data
    gotoAndPlay(2);
}

function loadSubDetailsError(event:IOErrorEvent):void
{
    output_txt.appendText("Connection failed");
}
    

And here’s the PHP code:


<?php

    // Create a database connection
    $connection = mysql_connect(EDITED OUT!);
    
    if (!$connection)
    {
        die("Database connection failed: " . mysql_error());
    }

    // Select a database to use
    $db_select = mysql_select_db("a3070991_TEST", $connection);
    
    if (!$db_select)
    {
        die("Database connection failed: " . mysql_error());
    }
    
    
    // Get values passed from Flash
    $Name = $_POST['Name'];
    $Age = $_POST['Age'];
    $Gender = $_POST['Gender'];

    // Add to subjects list
         
      $query = "INSERT INTO subjects (Name, Age, Gender) VALUES ('{$Name}', {$Age}, '{$Gender}')";
      mysql_query($query, $connection);
    

    //this gets the unique id for this participant and returns it to flash
    $returnID = mysql_insert_id($connection); 
    echo $returnID;

    // Close connection
    mysql_close($connection);

?>

So, this seemed to be working fine. I could set up a dynamic text box to display the returned ID field. But, when I went to use this value later on, it didn’t seem to be recognised as an integer. In fact, when I send it back to another PHP file it seems it’s stored as a stringArray. If I try to force it to int, it doesn’t work. Is there a way to do this, or a way to pass it from PHP to AS3 as an integer, for use at a later stage.

I found something on changing “dataFormat” to VARIABLES, and gave this a go, but I didn’t understand how to parse the huge return string you get back.

Thanks.