Saving HTML Form Data into an XML file using PHP
Posted: Fri Sep 17, 2004 5:36 am
Firstly, I am new to this site and so i hope i am putting this in the right place. Apologies if not.
Secondly i should say i am only just beginning to learn php so a lot of functions still mean little to me.
My problem is:
I am trying to create a guest book / message board for my website. It will only be used by a few people so traffic will not be high. I have created an HTML form where name and message can be put in. There is then an xml file which the form data is supposed to get stored in. I am trying to write the php script that will take the data from the form and put it into the xml file. This is what i have tried:
The problem with this is that that i end up with more than one (sorry don't know correct terminology) "primary" tag, so the file cannot be opened. I therefore assume i need to be able to add eg. <guestbook> </guestbook> at the start and end of the file. In which case - how do i write the information inside these tags.
Many thanks
Secondly i should say i am only just beginning to learn php so a lot of functions still mean little to me.
My problem is:
I am trying to create a guest book / message board for my website. It will only be used by a few people so traffic will not be high. I have created an HTML form where name and message can be put in. There is then an xml file which the form data is supposed to get stored in. I am trying to write the php script that will take the data from the form and put it into the xml file. This is what i have tried:
Code: Select all
<?php
$xml_string =
"<guest>
<name>$name</name>
<message>$message</message>
</guest>
";
$pagename = "guest.xml";
$fp=fopen("/inet/www.richard-ward.co.uk/html/".$pagename, "a+");
fwrite($fp, $xml_string);
fclose($fp);
print("Data sent to guest.xml");
?>Many thanks