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

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
king1033
Forum Newbie
Posts: 2
Joined: Sat Jul 10, 2004 11:31 pm

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

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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");
Post Reply