So I am trying to write to an xml file.

When I do it, NO SYNTAX comes up! BUT, When I go to the xml file it's supposed to write to it looks untouched and none of the data is there.

here is my PHP code:

$xmldoc = new DomDocument( '1.0' );
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;

$productNum = $_GET["lastm"];
$name = $_GET["docname"];
$category = $_GET["type"];
$content = $_GET["url"];
$user = $_COOKIE["username"];

if( $xml = file_get_contents("" . $user . "/docs.xml") ) {
    $xmldoc->loadXML( $xml, LIBXML_NOBLANKS );

    // find the headercontent tag
    $root = $xmldoc->getElementsByTagName('documents')->item(0);

    // create the <product> tag
    $product = $xmldoc->createElement('document');
    $numAttribute = $xmldoc->createAttribute("lastm");
    $numAttribute->value = $productNum;
    echo "Saving...";

    // add the product tag before the first element in the <headercontent> tag
    $root->insertBefore( $product, $root->firstChild );

    // create other elements and add it to the <product> tag.
    $nameElement = $xmldoc->createElement('name');
    $nameText = $xmldoc->createTextNode($name);

    $categoryElement = $xmldoc->createElement('type');
    $categoryText = $xmldoc->createTextNode($category);

    $urlElement = $xmldoc->createElement('url');
    $urlText = $xmldoc->createTextNode($content);

    $xmldoc->save("" . $user . "/docs.xml");
    echo "All Changes Saved in Office.";


Why won't it write to the xml file?

does your webserver has writing permision on that xml?

so what should I do?

are you asking how to check for file permisions?
that depens on your server (windows/linux/..)

Can we see the docs.xml you are trying to add the new entries?