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.
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.