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:
<?php
if(isset($_POST['submit']))
{
$mileage = $_POST['form'];
$file = fopen("data.xml","r+");
fwrite($file,$mileage);
fclose($file);
print_r(error_get_last());
}
?>
<form action= "" method="post" name="form">
<input type="hidden" value = "<?xml version='1.0' encoding='UTF-8'?>"/>
<input type="hidden" value="<miles>"/>
<span class="XMLsimpleType" onclick="selectelm(this, event);" ondblclick="selectelm(this, event);">
<label>Car: </label>
<input type="text" class="car" name="car" value="" onfocus="focusGained(this)" onchange="textChanged(this)" /></span>
<br/></span>
<br>
<span class="XMLsimpleType" onclick="selectelm(this, event);" ondblclick="selectelm(this, event);">
<span class="bike">
<label>Bike: </label>
<input type="text" class="bike" name="bike" value="" onfocus="focusGained(this)" onchange="textChanged(this)" /></span>
<br/></span>
<br>
<input type="hidden" value="</miles>"/>
<input type="submit" name="submit" value="submit"><br>
</form>
The form should create a properly formatted simple XML file that looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<miles>
<car>123</car>
<bike>245</bike>
</miles>
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?