Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
Adding data to an the XML file from form inputs

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
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda