AnswersLover
New Member
I am trying to figure out what I can do to create a code that appends data in my xml file not rewrite the xml file continuously. I need to be able to save all the form entries and as of right now every time the form is submitted it creates a new xml file and erases the old one. This may be really easy to fix or I am just really dumb but I have looked at DOM syntax and do not see what I coudl switch to change the outcome.\[code\]// define configuration file name and path$configFile = 'abook.xml';// if form not yet submitted// display formif (!isset($_POST['submit'])) { // set up array with default parameters $data = http://stackoverflow.com/questions/13718331/array(); $data['name'] = null; $data['email'] = null; $data['caddress'] = null; $data['city'] = null; $data['state'] = null; $data['zipcode'] = null; $data['phone'] = null; $data['pug'] = null; $data['comment'] = null; $data['subscribe'] = null; // read current configuration values // use them to pre-fill the form if (file_exists($configFile)) { $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->load($configFile); $address = $doc->getElementsByTagName('address'); foreach ($address->item(0)->childNodes as $node) { $data[$node->nodeName] = $node->nodeValue; } }\[/code\]In between is php form and validation code and at the end I use xml tags again:\[code\] // generate new XML document $doc = new DOMDocument(); // create and attach root element <configuration> $root = $doc->createElement('addressbook'); $configuration = $doc->appendChild($root); // create and attach <oven> element under <configuration> $address = $doc->createElement('address'); $configuration->appendChild($address); // write each configuration value to the file foreach ($config as $key => $value) { if (trim($value) != '') { $elem = $doc->createElement($key); $text = $doc->createTextNode($value); $address->appendChild($elem); $elem->appendChild($text); } } // format XML output // save XML file $doc->formatOutput = true; $doc->save($configFile) or die('ERROR: Cannot write configuration file'); echo 'Thank you for filling out an application.';} \[/code\]I am really new at this so I am sorry if my code is pretty messy. The second part is I am dealing with an xsl file which I have linked to my xml file but no matter what syntax I have used to transform nothing works to save it in a table. Again, I don't know if this could be caused by the why I have set up my php to write the XML...