PDA

View Full Version : Trying to write an xml file via php from flash - code inside


repenttokyo
11-28-2005, 11:14 PM
I am trying to send an xml string to a php file that will write this string into an xml file. It creates the file, but does not write any data. A friend and I have been beating our heads against the wall with this. Note: it doesn't even seem like data is being received by the script at all....

Here is the actionscript for the simple form:

// Add values to the labels.
clblEmail.text = "Please enter your email:";



// Create the listener object for the Button.
var oListener:Object = new Object();
oListener.click = function(oEvent:Object):Void {
// Get the email and selected products.
var sEmail:String = ctiEmail.text;

//Create the XML string containing the data from the input form
var sXMLData:String = "<formdata><email>" + sEmail + "</email></formdata>";

// Create the XML object for sending the data.
var xmlSender:XML = new XML(sXMLData);

//Create the XML object for receipt.
var xmlReceipt:XML = new XML();
xmlReceipt.onLoad = function():Void {
trace("receipt");
};

//Send the XML data to the server-side script using
//HTTP Get.
xmlSender.sendAndLoad("brent.php", xmlReceipt, "GET");
};

cbtSubmit.label = "Submit";
cbtSubmit.addEventListener("click", oListener);


And here is the php file:

<?php

// apparantly (hopefully) this gets the data from your other script (no way to test it properly)
$data = $_SERVER['QUERY_STRING'];


print "-----------<br>";
print $data;
print "<br>-----------<br>";

// hopefully your data looks like this ..
// #$data="<formdata><email>ben@ben.com</email><email>ben1@ben1.com</email><email>ben2@ben2.com</email></formdata>";

// xml parser crap
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLD ING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHIT E,1);
xml_parse_into_struct($parser,$data,$values,$tags) ;
xml_parser_free($parser);

// open the file
$handle = fopen ("asb.txt", "a");

// loop through the structures
for($i = 0; $i < count($values); $i++) {
if($values[$i]["tag"] == "email") {
$email = $values[$i]["value"];

// here $email is the name of whatever tag you use for the data you want
echo "e-mail #$i: $email<br>";

// write the data to the file
fwrite($handle, "$email\n");

// close the two loops
}
}

// also your original script didn't close the file ...
fclose($handle);

?>


ANY help would be appreciated! Thank you.

Flash Gordon
11-29-2005, 05:33 AM
why $data = $_SERVER['QUERY_STRING']; ????????
'QUERY_STRING'
The query string, if any, via which the page was accessed.

You didn't really helps us out there too much: format the code and tell us what $data echo's?

repenttokyo
11-29-2005, 06:55 AM
why $data = $_SERVER['QUERY_STRING']; ????????


You didn't really helps us out there too much: format the code and tell us what $data echo's?


i don't have your answer - i don't know a lot about php :( It was an example I had come across in a tutorial I had been using that accomplished roughly the same thing.....

so far, it appears as thought NO data is being passed to the php file and I don't understand HOW to pass data to the php file. it's very frustrating and i can find only limited documentation about how this is supposed to work re: actionscript / php.