I’m not claiming to be a great developer. look at this:
<?php
$xmlString = $HTTP_RAW_POST_DATA;
if (is_null($xmlString)) {
print “No data was sent”;
}
else {
$file = fopen(“guestbook.xml”, “w+”) or die(“Can’t open XML file”);
if(!fwrite($file, $xmlString)){
print “Error writing to XML-file”;
}
print $xmlString."
";
fclose($file);
}
?>
The tutorial goes on and talks about “The third ‘if’ statement writes to the file…”
Maybe that’s true, but there’s no thrid ‘if’ statement in this script. And that is why this script doesn’t work, this php script doesn’t Write to any file, but it DOES ERASE the file it’s supposed to be writing to.
Please recommend to your authors that smoking pot is ok, AFTER you proofread an upload.
meatcake - you may want to contact the author directly about that. I’m willing to bet it was just a typo, for I and numerous others have not had any issues getting the guestbook to work using his instructions
I’m sorry for the tone in the post.
kirupies has taught me more than any other source anywhere.
I wrote this after about an hour of thinking I was insane for not getting it to work.
-mike
if(!fwrite($file, $xmlString)){
print “Error writing to XML-file”;
}
what’s the ’ ! ’ for ?
The script above does NOT write to an XML file, my friend.
agian though: is $HTTP_RAW_POST_DATA only in php version 5 ?
because I’m using 4 and there’s no such global. It’s not at www.php.net dictionary either.
and um,… what’s get_file_contents ???
you mean file_get_contents
mbyae i sohlud tpye all my cdoe lkie tihs it mgiht wrok tehn
And yes I meant that fwrite. The “!” is a not operator. It reverses a boolean. fwrite returns false if it was not successful (Im sure you could have looked this up at php.net to which you are so attached). So, that if statement checks to see if fwrite write was successful. If it wasnt you get a !false or true and the code block below is executed which conveniently returns “Error writing to XML-file”;
As I said before, its obviously working in the tutorial example so the code is not flawed. Something is just wrong on your end and you’ll need some debugging to figure it out. Maybe your permissions aren’t set right or you’ve mistyped a filename or maybe even your working with an older incompatible version of PHP - something, but the code, as you can see, works.