So, i have a form that collects data. When the submit button is clicked, a new xml file is created in the destination folder with all the information that the user entered as shown below. But the second time when the form is filled and submitted, instead of adding the data to the newly created XML file, it is just replacing the data that was already there with the new information that the user entered on the second submission. I want it so that every time a user submit the form it keeps on adding data to the XML.
<?php
if (isset($_POST['frmSubmit'])) {
$xml = new DOMDocument("1.0","UTF-8");
$xml->formatOutput=true;
$xml->preserveWhiteSpace=false;
$students = $xml->createElement("students");
$xml->appendChild($students);
$xml->save('file.xml') or die("Error, Unable to create XML file");
$xml->load("file.xml");
$root = $xml->getElementsByTagName("students")->item(0);
$student=$xml->createElement("student");
$surname = $xml->createElement("surname",$_POST['surname']);
$student->appendChild($surname);
$name = $xml->createElement("name",$_POST['name']);
$student->appendChild($name);
$address = $xml->createElement("address",$_POST['address']);
$student->appendChild($address);
$email = $xml->createElement("email",$_POST['email']);
$student->appendChild($email);
$telephone = $xml->createElement("telephone",$_POST['telephone']);
$student->appendChild($telephone);
$root->appendChild($student);
//echo "<xmp>".$xml->saveXML()."</xmp>";
$xml->save("file.xml") or die("Error, Unable to create XML file");
}
?>
```[So, as shown in the screenshot below, instead of adding a new student child, it is replacing the current one][1]
[I want this][2]
[1]: https://i.stack.imgur.com/f804N.jpg
[2]: https://i.stack.imgur.com/Y5NAY.jpg