title: Saving HTML form data to XML file
body: <p>I'm trying to save the results of an HTML form to an XML file for later processing.  The form has Unfortunately, it looks like I can only save one answer at a time, but I'd like to write all the answers in the XML file.  Here is what I tried:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  if(isset($_POST['submit']))
  {
      $mileage = $_POST['form'];
      $file = fopen("data.xml","r+");
      fwrite($file,$mileage);
      fclose($file); 
      print_r(error_get_last());
  }
  ?&gt;
  
  &lt;form action= "" method="post" name="form"&gt;
  &lt;input type="hidden" value = "&lt;?xml version='1.0' encoding='UTF-8'?&gt;"/&gt;
  &lt;input type="hidden" value="&lt;miles&gt;"/&gt;
  &lt;span class="XMLsimpleType" onclick="selectelm(this, event);" ondblclick="selectelm(this, event);"&gt;
  &lt;label&gt;Car: &lt;/label&gt;
  &lt;input type="text" class="car" name="car" value="" onfocus="focusGained(this)" onchange="textChanged(this)" /&gt;&lt;/span&gt;
  &lt;br/&gt;&lt;/span&gt;
  &lt;br&gt;
  &lt;span class="XMLsimpleType" onclick="selectelm(this, event);" ondblclick="selectelm(this, event);"&gt;
  &lt;span class="bike"&gt;
  &lt;label&gt;Bike: &lt;/label&gt;
  &lt;input type="text" class="bike" name="bike" value="" onfocus="focusGained(this)" onchange="textChanged(this)" /&gt;&lt;/span&gt;
  &lt;br/&gt;&lt;/span&gt;
  &lt;br&gt;
  &lt;input type="hidden" value="&lt;/miles&gt;"/&gt;
  &lt;input type="submit" name="submit" value="submit"&gt;&lt;br&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The form should create a properly formatted simple XML file that looks like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;miles&gt;
  &lt;car&gt;123&lt;/car&gt;
  &lt;bike&gt;245&lt;/bike&gt;
  &lt;/miles&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I've spent the past four hours looking at this, and I know I can make it simpler, but first I'd like to just get it working.  I can write a single form entry, but not the whole form with the XML information.  What have I done wrong?</p>