Hi all,

I'm having an issue that I hope someone can help me out with.

I'm building a Flash app for a University project which uses PHP and an MS Access database (Not my choice, believe me LOL)

Anyway, what supposed to happen is that a user enters a username and password, and based on that produces a list of School Students.

I have the PHP working and outputting the data as XML which I'm trying to get Flash to read back in.

The problem is, that the data doesn't get returned to Flash, now I'm sure it's something I'm doing wrong in regards to passing the information from the flash form to the PHP file, but I can't figure out what the problem is.

This is the PHP I'm using, which works using a seperate HTML form that I put together to test it.

<?php 

//=====================================// 
// gets data from form, may be an empty string 

$sUsername = $_POST["Username"]; 
$sPassword = $_POST["Password"]; 

//=====================================// 
// Database Section 
//=====================================// 
// creates a new Common-Object-Model (COM) connection object 

$adoCon = new COM("ADODB.Connection"); 

// the path to the folder holding this PHP script 

$sHere = dirname(__FILE__); 

// opens the connection using a standard Access connection string 

$adoCon->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$sHere/Registerdbs.mdb"); 

$sSQL=    "SELECT * FROM tblPupilInfo WHERE class LIKE 
    (SELECT currentclass FROM tblStaffLogin WHERE Username LIKE '$sUsername' and Password LIKE '$sPassword')"; 



// searches the DB 
    $rsMain = $adoCon->Execute( $sSQL ); 

//=====================================// 
// Begins Creating XML Formated Code 

echo "<?xml version=\"1.0\"?>\n"; 
echo "<pupils>\n"; 

//=====================================// 
// Assigns Query results to variable for use later 

while (!$rsMain->EOF) 
{    // gets each of the fields 
    $sPupilID = $rsMain->Fields("ID")->value; 
    $sPupilSurname = $rsMain->Fields("Surname")->value; 
    $sPupilForename = $rsMain->Fields("Forename")->value; 
    $sPupilDOB = $rsMain->Fields("DOB")->value; 
    $sPupilAddress = $rsMain->Fields("Address")->value; 
    $sPupilEmergency = $rsMain->Fields("Emergency Contact")->value; 
    $sPupilClass = $rsMain->Fields("Class")->value; 

//=====================================// 
// Continues Creating XML Formated Code 


    echo "<surname>" . $sPupilSurname . "</surname>\n"; 
    echo "<forename>" . $sPupilForename . "</forename>\n"; 
    echo "<dob>" . $sPupilDOB . "</dob>\n"; 
    echo "<address>" . $sPupilAddress . "</address>\n"; 
    echo "<contact>" . $sPupilEmergency . "</contact>\n"; 
    echo "<class>" . $sPupilClass . "</class>\n"; 

    // moves to the next record OR runs out of records (hits end of recordset) 
    $rsMain->MoveNext(); 
} 

//=====================================// 
// Concludes Creating XML Formated Code 
echo "</pupils>\n"; 



//=====================================// 
// closes the recordset, frees up resources, kills all traces 
    $rsMain->Close(); 
    $rsMain->Release(); 
    $rsMain = null; 

// closes the connection, frees up resources, kills all traces 
    $adoCon->Close(); 
    $adoCon = null; 

?> 

As you can see the PHP formats the output data into XML, which I then want to Flash to read.

I have two pieces of action script that I am using

Frame 1 - Simple 2 field form, which needs to pass the input from the fields to the PHP

LoginButton.onPress = function() {

//create varObject for sendingData
var lvoutput:LoadVars = new LoadVars();
lvoutput.Username = txtUsername.text;
lvoutput.Password = txtPassword.text;

//create xmlObject for returnData
var returnedData:XML = new XML();            
returnedData.ignoreWhite = true; returnedData.onLoad = function(success){ if (!success) { trace("failed to load/find php script"); }else{ //check for error XML or valid XML, in LIVE version trace("PHP Script found"); //parse XML data trace("Returned XML: "+ newline + returnedData + newline); //I suggest dumping all data in array/object arrays for later use. //I also suggest you nest your clip that you want to go to frame 5 } } //make call to php script lvoutput.sendAndLoad("ReadDB3.php", returnedData, "POST"); gotoAndPlay(5); } stop();

When I run this code, the PHP file is found, but I get no XML returned to Flash.
I get the following in the Flash 'Output' Panel

PHP Script found
Returned XML:

As I said before, I'm pretty sure it's something to do with how I'm passing the inputs to the PHP, but can't figure it out.

Any help would be appreciated.

Thanks

TheMightySpud

    I know nothing about Flash but have done a fair bit of Flex.

    You need to run something like Fiddler to find out exactly what Flash is sending and PHP is returning.

      Well, your XML is semi-malformed. If you have more than one rowset returned, then you should encase each rowset inside of a group. So your XML should look something like:

      <?xml version="1.0"?>
      <pupils>
          <pupil>
              <surname></surname>
              <forename></forename>
              <dob></dob>
              <address></address>
              <contact></contact>
              <class></class>
          </pupil>
      </pupils>

      Now, to that end, you have some issues with how you're reading the XML. You can go here and read the article, you can fix it yourself pretty much 🙂 You're not that far off.

        Hi,

        Thanks for the responses. I had a look through that article, only to discover that it's for AS3, unfortunately, I'm limited to AS2 due to University resources. I'm sorry, I forgot to mention that in my initial post.

        I had a thought about my problem though.

        Instead of outputting the information via XML, would it be simpler to create an array with the variables that I need to pass back to flash? (ie. the results of the search).

        if so, could you possibly supply the correct syntax to do so as I can't seem to find it anywhere.

        Thanks again,

        TheMightySpud

          Write a Reply...