PDA

View Full Version : Appending to XML with PHP problem


jclarke
05-21-2006, 12:58 AM
Hey folks,
I've made a php code that is supposed to append form data to an xml file that is later read by flash.

my php code I have so far is as follows:

<?php

$ranNum = rand(1,1000);
echo "Your Random Id is: ".$ranNum."<br>\n";

$daUser=$_POST['userName'];
$daPass=$_POST['userPass'];
$daName=$_POST['usersName'];
$daMail=$_POST['userEmail'];

echo $daUser . "<br>\n";
echo $daPass . "<br>\n";
echo $daName . "<br>\n";
echo $daMail . "<br>\n";

$database = fopen("test.xml",'a');

$writeData = "<user" . $ranNum . ">\n ";
$writeData .= "<userName" . $ranNum . ">" . $daUser . "</userName" . $ranNum . ">\n ";
$writeData .= "<userPass" . $ranNum . ">" . $daPass . "</userPass" . $ranNum . ">\n ";
$writeData .= "<personName" . $ranNum . ">" . $daName . "</personName" . $ranNum . ">\n";
$writeData .= "</user" . $ranNum . ">\n\n";

echo $writeData . "<br>";


fwrite($database,$writeData);

fclose($database);

echo "<br>writing to file complete<br>";
?>



If anyone could tell me where I'm going wrong in terms of writing to the "test.xml" would be largly appreciated.

Thanks:)

jsebrech
05-22-2006, 12:04 PM
What sort of errors are you getting?

jclarke
05-22-2006, 12:25 PM
well none, really except the fact that it just doesn't write to the file?!!

im as baffled as you, though I have a hunch it might be a security setting.

apart from that, is there anyone else that can give me a clue as to why this code won't write to a file??

jsebrech
05-22-2006, 01:17 PM
PHP needs appropriate settings for writing set in the php.ini. Perhaps looking through the fopen documentation could rectify things. Also, aren't text files null-terminated? If you start writing after the last byte, then it would start writing after the null character, and all those characters you write would be discarded.

jclarke
05-28-2006, 10:55 PM
nah, that's what the 'a' thing as the second parameter in the fopen does it writes to a file starting at the end or where it wrote last.

But thanks for that hint with the ini file much apprecciated, i'll ask my head technition about that.

Thanks:)

jclarke
06-14-2006, 10:36 AM
don't worry i found the problem I asked the guy in charge to ebale write privelages for the folder and it works now.