Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!