Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 53289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:02:24+00:00 2026-05-10T17:02:24+00:00

I was trying to insert new data into an existing XML file, but it’s

  • 0

I was trying to insert new data into an existing XML file, but it’s not working. Here’s my xml file:

<list>     <activity>swimming</activity>     <activity>running</activity> <list> 

Now, my idea was making two files: an index page, where it displays what’s on the file and provides a field for inserting new elements, and a php page which will insert the data into the XML file. Here’s the code for index.php:

<html> <head><title>test</title></head> </head>  <?php     $xmldoc = new DOMDocument();     $xmldoc->load('sample.xml', LIBXML_NOBLANKS);      $activities = = $xmldoc->firstChild->firstChild;     if($activities!=null){         while(activities!=null){             echo $activities->textContent.'<br/>';             activities = activities->nextSibling.         }     } ?>  <form name='input' action='insert.php' method='post'>     insert activity:     <input type='text' name='activity'/>     <input type='submit' value='send'/> </form> </body> </html 

and here’s the code for insert.php:

<?php     header('Location:index.php');     $xmldoc = new DOMDocument();     $xmldoc->load('sample.xml');      $newAct = $_POST['activity'];      $root = $xmldoc->firstChild;      $newElement = $xmldoc->createElement('activity');     $root->appendChild($newElement);     $newText = $xmldoc->createTextNode($newAct);     $newElement->appendChild($newText);      $xmldoc->save('sample.xml'); ?> 

The user is to access index.php, where he would see a list of the current activities present in the XML file, and a text field below where he can insert new activities. Upon clicking the send button, the page would call insert.php, which contains a code that opens the XML file in a DOM tree, inserts a new node under the root node and calls back the index.php page, where the user should be able to see the list of activities, his new activity there under the others. It is not working. When i click on the button to submit a new entry, the pages refreshes and apparently nothing happens, the XML is the same as before. What did i do wrong? Also, i’d like to know if there’s a better way of doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:02:25+00:00Added an answer on May 10, 2026 at 5:02 pm

    is your code block copy and pasted from your existing files? if so i see two potential issues:

    <form name='input' action'insert.php' method='post'> // should be: <form name='input' action='insert.php' method='post'> 

    note: you’re missing action='insert.php', which would cause the form to just reload itself without submitting, which is the behaviour you describe.

    secondly, make sure you have write permission to ‘sample.xml’. you can confirm if you’re actually writing anything:

    print 'I wrote '.$xmldoc->save('sample.xml').' bytes of data'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you've got 2 choices here: 1.Implement drawing yourself… May 11, 2026 at 9:38 pm
  • Editorial Team
    Editorial Team added an answer A particular feature of a HashMap is that unlike, say,… May 11, 2026 at 9:38 pm
  • Editorial Team
    Editorial Team added an answer When working with a new code written by someone else,… May 11, 2026 at 9:38 pm

Related Questions

I was trying to insert new data into an existing XML file, but it's
I have a database table full of some really ugly and messy data. In
Hopefully I can do the problem justice, because it was too difficult to summarise
I was trying to TDD using SubSonic 2.1, MySQL and C# and when I
I am trying to trace a deadlock that is occurring in our SQL 2005

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.