note 76673 rejected from function.simplexml-load-file by nlopess
| From: | nlopess@php.net | Date: | Fri, 27 Jul 2007 11:40:19 +0000 |
| Subject: | note 76673 rejected from function.simplexml-load-file by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128966@lists.php.net to get a copy of this message | ||
Note Submitter: paul at christianpatriot dot us
----
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. The script returns no errors but doesn't access the
gbook.xml which has all permissions granted to everyone.
HELP PLEASE, it looks so simple :-) in the manual.
Reproduce code:
---------------
processgb.php
<?php
if (file_exists('gbook.xml')) {
$xml = simplexml_load_file('gbook.xml');
} else {
exit('Failed to open gbook.xml.');
}
$entry=$xml->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($xml,"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>