Instead of creating a new XML file each time, you'll want to load your existing XML file. To reuse as much of your code as possible, use SimpleXML's file-reading function:
// This file "test.xml" is pre-populated with your base XML:
// <?xml version="1.0" encoding="UTF-8"?><entrys></entrys>
$xml = simplexml_load_file('test.xml');
We need to make a change to your schema; <entrys>
should be an array-like node of <entry>
nodes. Correct? If so, replace your current addChild
methods by creating a parent node to capture the first name, last name etc.:
$entry = $xml->addChild('entry');
$entry->addChild('fname', $fname);
$entry->addChild('lname', $lname);
$entry->addChild('location', $location);
$entry->addChild('report', $report);
$entry->addChild('description', $description);
Running this twice, we'll get something like:
<?xml version="1.0" encoding="UTF-8"?>
<entrys>
<entry>
<fname>abc</fname>
<lname>abc</lname>
<location>abc</location>
<report>abc</report>
<description>abc</description>
</entry>
<entry>
<fname>abc</fname>
<lname>abc</lname>
<location>abc</location>
<report>abc</report>
<description>abc</description>
</entry>
</entrys>