Page 1 of 1

how to writw to the next line of a text file list

Posted: Sat Jul 10, 2004 11:31 pm
by king1033
Hi,
I am really new to php. this is my first night learning php. I was hoping someone can tell me the proper code so that when I try to update my text file via a form, it goes to the next line everytime, instead of writing over the name I already have there. Here is my code:

Code: Select all

<?php
$filename = "uploads/test.txt";
$fp = fopen($filename, "w") or die("Couldn't open $filename");
$entry = $_POST[email];
fwrite($fp, $entry);
fclose($fp);

?>
Thanks,
Jason


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Jul 10, 2004 11:38 pm
by feyd
First off, welcome to the board and PHP. Second, remember when posting code to use the

Code: Select all

bbTags.

Now, on your question: switching the "w" for "a" should fix it.

Additional note: make sure to quote 'email' in your array access of $_POST.. this could clear up a problem you may have later..

Posted: Sun Jul 11, 2004 3:26 am
by kettle_drum
You might also want to add \r\n so that it goes to a new line in the text file:

Code: Select all

fwrite($fp, $entry."\r\n");