I have an online form that submits info to a php script which in turn stores the data to an XML file (no mySQL access here).
The server is running PHP 4.4.2.
The submitted info is stored using DOM XML functions, such as (in outline):
<?php
//some code here
//$xml_field_names[] is array of names of to-be-xml-nodes
//$xml_field_values[] is array of received POST form values
$xml_path = "/some/path/file.xml";
if (!$dom = domxml_open_file($xml_path)) {
//the above requires absolute path
exit($error_wraper_user[0]."Could not access the XML resource. This is a system error. Please contact the admin.".$error_wraper_user[1]);
}
$root = $dom->document_element(); //obtain the root
$dom->preserveWhiteSpace = true;
$dom->formatOutput = true;
//create <person> node where all the submitted info is stored
$person_container = $dom->create_element("person");
$person_container = $root->append_child($person_container);
//create unique id for <person> container
$unique_id = mt_rand(100,999).time();
$person_container->set_attribute("id",$unique_id);
/////////////////////////////////////////////////
//start inputting the post vars into the xml file
/////////////////////////////////////////////////
for ($i = 0; $i <= count($xml_field_names)-1; $i++) { //cycle through the to-be xml nodes
//create a node within <person>
$newnode = $dom->create_element($xml_field_names[$i]);
$newnode = $person_container->append_child($newnode);
//write to the newly created node
$newnode_value = $dom->create_text_node("\n".$xml_field_values[$i]."\n");
$newnode_value = $newnode->append_child($newnode_value);
}
$dom->dump_file($xml_path, false, true); //save xml file
?>
So, the code doesn't look up anything, just opens the file, creates another node inside of which other nodes w/ info are written. The code works fine, the data is stored/retrieved (I have another admin php file to view the contents of the xml file nicely in a table).
However, lately I found that the last entry was getting truncated after it was written to a file.
For example, Mr. Smith submits his info, and after that I can go to my admin php file and view his submitted info. No problem there. Then a few hours later I try to view the info again and half of the last submitted info is missing!! and php gives me an error: domxml_open_file() Premature end of data in tag TAGNAME..
The xml file itself looks like someone opened it and deleted a bunch of lines at the very end of the file, including all the closing tags at the end. I have over 20 submitted forms stored and this is the 2nd time it occured.
I don't think php could make that error though, or could it? or is someone playing a trick on me here (several people have access to the server)? What is happening???
Please help!!