# An error in a tutorial (a nice one)

**URL:** <https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308>\
**Category:** Uncategorized\
**Created:** [August 26, 2004, 6:43pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308 "2004-08-26T18:43:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![meatcake](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@meatcake](https://forum.kirupa.com/u/meatcake)\
**Post date:** [August 26, 2004, 6:43pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/1 "2004-08-26T18:43:59Z")

</div>

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.

the source file is “processXML.php”

oh well  
mike

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 7:00pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/2 "2004-08-26T19:00:43Z")

</div>

Giving the name or the URL of the tutorial would help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 7:31pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/3 "2004-08-26T19:31:09Z")

</div>

its the guestbook tutorial

[http://www.kirupa.com/web/xml\_guestbook.htm](http://www.kirupa.com/web/xml_guestbook.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 10:42pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/4 "2004-08-26T22:42:53Z")

</div>

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 😊

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 12:45am UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/5 "2004-08-27T00:45:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 1:32am UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/6 "2004-08-27T01:32:16Z")

</div>

Hope you got it to work though 🙂 It’s a neat implementation of XML and Flash!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 27, 2004, 8:22am UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/7 "2004-08-27T08:22:28Z")

</div>

Have you posted in the forums about your problem? You can see that the example in the tutorial actually works so it might be something on your end.

Someone else had problems with it before and it was because of $HTTP\_RAW\_POST\_DATA;

You might want to try replacing that with

get\_file\_contents(“php://input”);

And see if that helps at all.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 10:19am UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/8 "2004-08-28T10:19:49Z")

</div>

Senoc - it is actually a small mistake in the tut.  
there’s no fwrite()

but the $HTTP\_RAW\_POST\_DATA might be only for php5 it’s not in the [php.net](http://php.net) dictionary.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 10:53am UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/9 "2004-08-28T10:53:40Z")

</div>

theres an fwrite in the code you posted above

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 2:15pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/10 "2004-08-28T14:15:00Z")

</div>

oh you mean this?

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](http://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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 2:51pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/11 "2004-08-28T14:51:56Z")

</div>

I’m not sure that it works only in PHP 5 because the site and forums are only PHP 4.3.3. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 28, 2004, 3:04pm UTC](https://forum.kirupa.com/t/an-error-in-a-tutorial-a-nice-one/62308/12 "2004-08-28T15:04:57Z")

</div>

excuse me for the typo. You knew what I meant

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](http://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.
