Problem with writing form contents to file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ramya4myself
Forum Newbie
Posts: 7
Joined: Sat Nov 07, 2009 2:46 pm

Problem with writing form contents to file

Post by ramya4myself »

Hello,

I am writing two php scripts one for form and other one to write the values of a form using php into a file and also print the values on the another html page. I dont know why it is not writing into the file but if I print the form values in the script, that is getting printed on the html page. The fopen should create the file but until I set the permissions manually it shows the error, " permission denied" on the html page. I even checked the path of the file. When I Execute the file, it directly goes to the else clause, "Cannot write to the file". Could anyone please help me with this. I am using this code for writing to the file:

Code: Select all

$filename="test.txt";
 
if(is_writable($filename)){
if(!$fp = fopen($filename,'a')){
echo "cannot open file($filename)";
exit;
}
if($fp!=null)
{
fwrite($fp,$name);
fwrite($fp,$date);
fwrite($fp,$platform);
fwrite($fp,$browser);
fwrite($fp,$comments);
}
fclose($fp);
}
else
{
echo "Cannot write to the file";
}
 
Thanks

Ramya
ramya4myself
Forum Newbie
Posts: 7
Joined: Sat Nov 07, 2009 2:46 pm

Re: Problem with writing form contents to file

Post by ramya4myself »

I even tried by editing the code but I could not succeed in writing to the file. I says permission whenever I use this.

Code: Select all

$filename="test.txt";
 $fp = fopen($filename,'a')
 
 if($fp!=null)
 {
 fwrite($fp,$name);
 fwrite($fp,$date);
 fwrite($fp,$platform);
 fwrite($fp,$browser);
 fwrite($fp,$comments);
 }
 fclose($fp)
;

thanks
ramya4myself
Forum Newbie
Posts: 7
Joined: Sat Nov 07, 2009 2:46 pm

Re: Problem with writing form contents to file

Post by ramya4myself »

Thanks.
I could solve writing into a file but I want the filename in a particular directory like PHP/Peter.txt. This is not happening even though I set the permissions of the file and the directory. It displays an error "fopen cannot open directory: Is a directory /PHP/Peter.txt ". Could anyone please help me with this. I am using putty server in Window XP.
Post Reply