How can I take user input and save it to an XML file in PHP?
I’d like to create a simple form in PHP where the user enters a little bit of information, which gets saved to an XML file on the server. This XML file should then be able to have the data in it read by PHP and manipulated… How would I do this?
First, make a submit button to your website:
<input type="submit" value="create xml">
Second, add code like this to the top of the website to grab submissions.
<?php
if (isset($_GET['value1']) && isset($_GET['value2']))
{
$xmlstring = "<blah><value1>" + $_GET['value1'] + "</value1><value2>" + isset($_GET['value2']) + "</value2></blah>"
$myFile = "test.xml";
$filestream = fopen($myFile, ‘w’);
fwrite($filestream, $xmlstring);
exit(1);
}
?>
http://simonwillison.net/2003/Apr/29/xmlWriter/
There’s a great answer for this over on Experts Exchange.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_23299970.html
In short you will use fwrite() command to write the data to an xml file with the post values received from your form.