Jump to content

Fwrite


jarrett000

Recommended Posts

I know how to write a submited text into a .txt file with fwrite(), but my problem is that when a user inputes their name and the PHP writes it into the file, ir erases the old name.Here's my script:

				$FNN = fopen("NameLog.txt", "r");				$read = fread($FNN, 1024);				fclose($FNN); 				$FNN = fopen("NameLog.txt", "w"); 				fwrite($FNN, $name); 				fclose($FNN);

All I need to do is have this happen without erasing the previous name.

Link to comment
Share on other sites

Append to the file instead of writing to it. To do so, use "a" or "a+" as the fopen mode (as opposed to "w").Also (and this is not a must, it's just what I'd do), consider using file_put_contents() if possible, like so:

file_put_contents('NameLog.txt', $name, FILE_APPEND);

Alternatively, read in the whole file first, write it out into the new file, and only then write the new contents.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...