Page 1 of 1

Writing to a file. Basic but I cant seem to get it to write!

Posted: Tue Mar 02, 2004 11:43 am
by Joe
Recently I have been trying to create a small comment area where people who enter my site can enter comments and suggestions. I want the users name and their message to be written into a text file name comments.txt so others also have the ability to view it. Its very basic I know but it could help me a lot. Now the problem is when i press the submit button on the form it shows up saying that the file comments.txt is not writeable. The files are all in the right directorys aswell as the comments.txt file. Has anyone ever had a problem similar to this?. If so could you please help me!

My code for this project go's like:

<?php
$filename = "comments.txt";
$name = $_POST["username"];
$comments = $_POST["comments"];

if (is_writable($filename))
{

if (!$handle = fopen($filename, 'b'))
{
echo "Cannot open file ($filename)";
exit;
}

if (fwrite($handle, $name, $comments) === FALSE)
{
echo "Error, Cannot write to file ($filename)";
exit;
}

echo "<b>Thank you, $name.</b><p> ($comments)";
fclose($handle);
}
else
{
echo "The file $filename is not writable.";
}
?>


Regards



Joe 8)

Posted: Tue Mar 02, 2004 12:06 pm
by pickle
'b' is not an option for fopen(). Try using 'a+'

fopen documentation:
http://ca3.php.net/manual/en/function.fopen.php

Still not working!

Posted: Tue Mar 02, 2004 12:48 pm
by Joe
Tried a+ and a with no luck at all. Any help appreciated!


Joe

Posted: Tue Mar 02, 2004 2:31 pm
by ol4pr0
w w+ ....

Any errors youre getting ?