im creating a very simple CMS
panel for my website(i'm still lerning). And I have some problems. I've created the panel in Flash-AS3
, which loads the php
file, which opens and saves the xml data
. Here are the codes:
AS3 code:
function onClicked(e:MouseEvent):void
{
var myXmlString:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?><NEWSCONTENT><NEWS ID=\"" + idTxt.text + "\" IMG=\"" + sourceTxt.text +"\" TITLE=\"" + titleTxt.text + "\" DATE=\"" + dateTxt.text + "\" CONTENT=\"" + contentTxt.text + "\"/></NEWSCONTENT>";
trace(myXmlString);
var myXml:XML = new XML(myXmlString);
var req:URLRequest = new URLRequest("phpXML.php");
req.data = myXml;
req.contentType = "text/xml";
req.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
function onPHPLoaded(e:Event):void
{
statusTxt.text = "Dane zostaly zaktualizowane!";
}
loader.load(req);
loader.addEventListener(Event.COMPLETE, onPHPLoaded);
}
send_btn.addEventListener(MouseEvent.CLICK, onClicked);
PHP code:
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
$xml = $GLOBALS["HTTP_RAW_POST_DATA"];
$file = fopen("www.xml", "w");
fwrite($file, $xml);
fclose($file);
echo ($GLOBALS["HTTP_RAW_POST_DATA"]);
}
?>
XML code:
<?xml version="1.0" encoding="utf-8"?>
<NEWSCONTENT>
<NEWS ID="1" IMG="galerry/1b.jpg" TITLE="Let's begin!" DATE="23-11-2014" CONTENT="This is the content"/>
</NEWSCONTENT>
Everything works fine without errors
, but it's not working the way I want to.
Now when I put data/"strings"
to the text fields
it removes all xml data
and saves it again with the text i wrote. But i want to to add a next line "<NEWS ID="1" IMG="galerry/1b.jpg" TITLE="Let's begin!" DATE="23-11-2014" CONTENT="This is the content"/>"
to the xml
file.
I tried to change the: $file = fopen("www.xml", "w");
to $file = fopen("www.xml", "a");
, but this added whole xml
code again to the first.
Can anyone help?
No comments:
Post a Comment