write data to a file wich received from GET

Post Reply
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

write data to a file wich received from GET

Post by Rksk » Wed Jun 02, 2010 4:17 pm

I use this script to Write data to a file wich sent from GET method.
But it doen't write datas with sent as 2nd time.
it writes data the file at only 1st time.

Code: Select all

if (isset($_GET['t'])) {


if (!file_exists("list.html"))
{
  $myFile = "list.html";
  $fh = fopen($myFile, 'w');
  $stringData = "\n";
  fwrite($fh, $stringData);
  fclose($fh);
}

$myFile2 = "list.html";
$fh2 = fopen($myFile2, 'a');
$stringData2 = $_GET['t']."<br> \n <br><p>";
fwrite($fh2, $stringData2);
fclose($fh2);

echo "\n complete";

} 
what is the bug? i'm having a trouble with it!
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: write data to a file wich received from GET

Post by Neo » Wed Jun 02, 2010 4:57 pm

fopen ( filename , 'a' ) will create a file if not exists. So first thing is you don't need to have the first part to create a file if it is not exists with 'w'. Just remove it and see whether it works.

To see how many bytes the fwrite has written, you may use echo fwrite(.......);
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: write data to a file wich received from GET

Post by Rksk » Wed Jun 02, 2010 5:20 pm

Thakz neo.
it's working
Post Reply

Return to “PHP & MySQL”