Entonces, tengo un formulario que recopila datos. Cuando se hace clic en el botón Enviar, se crea un nuevo archivo xml en la carpeta de destino con toda la información que el usuario ingresó, como se muestra a continuación. Pero la segunda vez, cuando se completa y envía el formulario, en lugar de agregar los datos al archivo XML recién creado, simplemente reemplaza los datos que ya estaban allí con la nueva información que el usuario ingresó en el segundo envío. Lo quiero para que cada vez que un usuario envíe el formulario, siga agregando datos al 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