|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-25 14:28 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
Description: ------------ Attempting to append child/attributes to an existing xml file using post data from an html form. Post data gets passed fine, but it seems the xml file is never opened or loaded. Since I don't think the file is ever opened, I am unable to (attempt to) write the new data to the file. Reproduce code: --------------- processgb.php <?php $xml = simplexml_load_file('gbook.xml'); $sxe = new SimpleXMLElement($xml); $entry=$sxe->addChild('entry'); $entry->addAttribute('date',date("Y-m-d")); $entry->addChild('name',$_POST["name"]); $entry->addChild('email',$_POST["email"]); $entry->addChild('homepage',$_POST["homepage"]); $entry->addChild('country',$_POST["country"]); $entry->addChild('comment',$_POST["comment"]); $result=file_put_contents($sxe,"gbook.xml"); if ($result<1 or result==false): echo 'error writing: '.$result; endif; ?> XML structure: <?xml version="1.0" encoding="utf-8" ?> <guestbook> <entry date=""> <name></name> <email></email> <homepage></homepage> <country></country> <comment></comment> </entry> </guestbook> Expected result: ---------------- The new data is added to the xml file. Actual result: -------------- PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /usr/local/apache2/htdocs/ssa/9112001/guestbook/processgb.php:9 Stack trace: #0 /usr/local/apache2/htdocs/ssa/9112001/guestbook/processgb.php(9): SimpleXMLElement->__construct('') #1 {main} thrown in /usr/local/apache2/htdocs/ssa/9112001/guestbook/processgb.php on line 9