# Need help sending data to xml

**URL:** <https://forum.kirupa.com/t/need-help-sending-data-to-xml/273021>\
**Category:** Uncategorized\
**Created:** [October 10, 2008, 9:50am UTC](https://forum.kirupa.com/t/need-help-sending-data-to-xml/273021 "2008-10-10T09:50:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![snail28](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@snail28](https://forum.kirupa.com/u/snail28)\
**Post date:** [October 10, 2008, 9:50am UTC](https://forum.kirupa.com/t/need-help-sending-data-to-xml/273021/1 "2008-10-10T09:50:17Z")

</div>

ok…let’s go to the point of my problem…

i have a script like this,

```auto

// create an XML object
var doc:XML = new XML();

// create three XML nodes using createElement()
var element1:XMLNode = doc.createElement("level");

// place the new nodes into the XML tree
doc.appendChild(element1);
element1.appendChild(element2);

listenerKey.onKeyDown = function(){
		
		//save data into variable
		Rec.keycode = Key.getCode().toString();
		Rec.beatTime = (getTimer() / 100).toString();
		dataRec.push(Rec);
		
		var keycode_node:XMLNode = doc.createElement("keyCode");
		keycode_node.appendChild( doc.createTextNode( Rec.keycode ) );
		
		var beatTime_node:XMLNode = doc.createElement("beatTime");
		beatTime_node.appendChild( doc.createTextNode( Rec.beatTime ) );
		
		//place data into xml tree
		element1.appendChild(keycode_node)
		element1.appendChild(beatTime_node)
		trace (doc);
		
		
}

this.button_mc.onRelease = function(){
	
	doc.contentType = "text/xml";
	doc.send("http://server/andy/write.php","_blank");
	

}

```

its all about, i was try to make an xml object in flash, and all i want to do is send the ‘doc’ (which is xml object contained xml data) via php, (which you can see the file is write.php) and i want php to save/write it into an xml document… do you get it ?

here’s my php

```php

<?php	

//error handler function
function customError($errno, $errstr)
{ 
 
echo "<b>Error:</b> [$errno] $errstr";
 
}

//set error handler
set_error_handler('customError');

//trigger error
$string = $_POST['doc'];
// declare a variable and assign the text sent to this script

$file = fopen("stage1.xml", 'w+');
// for the meaning of the second parameter check http://tr2.php.net/fopen
// but this basically opens the file if it exists or creates it. use double
// period for upper directories like "../somefile.txt'

$write = fwrite($file,"$HTTP_RAW_POST_DATA");

//$write = fwrite($file, $string);
// this variable returns false if this file can not be edited.
// parameter1 is the reference of the file, parameter2 is the string to write

if ($write) {
	echo "<br>&result=success&</br>";
	// use ambersand sign before the variable name and after the value for flash
	// and note that whatever the type of value it will be a string in flash
} else {
	
	echo "<br>&result=failure&</br>";
}
fclose($file);

?>

 

```

and the problem is, everytime i run the flash, and send the data , then browser will automatically open, and it always show

&result=failure, error[8] Undefined index:doc

and stage1.xml is blank…

all i want to do is the doc which traced everytime i press a key on keyboard (see script above) and saved to doc variable saved into an xml document…

please help me solve this problem cause im getting frustrated finding the solution ☹
