From: paul at christianpatriot dot us
Operating system: Linux
PHP version: 5.2.3
PHP Bug Type: SimpleXML related
Bug description: Unable to open xml via SimpleXML
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
--
Edit bug report at http://bugs.php.net/?id=42092&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42092&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42092&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42092&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42092&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42092&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42092&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42092&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42092&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42092&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42092&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42092&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42092&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42092&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42092&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42092&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42092&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42092&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42092&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42092&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42092&r=mysqlcfg