Forum Moderators: coopster

Message Too Old, No Replies

error in writing XML file with php

create XML format file with php

         

phparion

6:50 am on May 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi

I have written a script that reads Name and Email of the user from database and then I write all values in XML format onto an already existing file "list.xml".

list.xml contains this line already,

Code:
<?xml version="1.0" encoding="UTF-8"?>

here is what i have done so far

PHP Code:
global $fname;
$fname = "list".".xml";
global $fp;

DATABASE Connection etc to get names in $names array and emails in $email array

PHP Code:
if($fp = fopen($fname,"a")) {
fputs($fp,"<emailscript>\r\n");
fputs($fp,"<retunrrow>\r\n");
fputs($fp,"<fullname>" .$names[$i]. "</fullname>\r\n");
fputs($fp,"<fullemail>" .$emails[$i]. "</fullemail>\r\n");
fputs($fp,"<retunrrow>\r\n");
fputs($fp,"</emailscript>\r\n");
}
else die("SORRY");
//after loop is ended

fclose($fp);


First of all it is giving me error for fclose($fp);

Code:
Warning: fclose(): supplied argument is not a valid stream resource in /home/#*$!/public_html/xxx/write.php on line 78

if i comment this line that it doesnt do anything, it just shows a blank white page, when i check the list.xml file it has nothing written onto it as a result of loop.

I am not sure what's going wrong with this, can anybody help please?

Gero_Master

10:16 am on May 6, 2006 (gmt 0)

10+ Year Member



I have used PHP to make RSS feeds which gain info from DB.

I managed to fix that error (I had it too).

Tip:

XML seems to be pretty sensitive. Make sure the scripting starts from very top of the page.

not like:
echo "
XML CODE
";

LIKE THIS:
echo "XML CODE";

phparion

11:09 am on May 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it had nothing to do with XML code, it was all php, anyway, i have sold it i hadnt permission to write on the xml file so i changed its permission to 777 and now it is working fine.

thanks

Gero_Master

7:21 pm on May 6, 2006 (gmt 0)

10+ Year Member



Ok!

Nice to know you got it working anyways :)