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
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Sun Nov 23, 2003 9:39 pm
i wrote a script to process a form and write the given fields to a flat file (text file), the problem i'm having is every time i try to use the script to add something to the txt file, it overwrites the contents of the entire file.
Code: Select all
<?php
if((!isset($_POST['name'])) or (!isset($_POST['link'])) or (!isset($_POST['info'])))
{
echo 'You must enter <b>ALL</b> fields before you can continue!';
exit;
}
$name = $_POST['name'];
$link = $_POST['link'];
$info = $_POST['info'];
$fp = fopen("download.txt", "w+");
$insertcode = "<table width='100%' border='0' cellspacing='1' cellpadding='2' bgcolor='#dcdcdc' align='center'><tr><td width='200' border='1' bgcolor='whitesmoke'>".$name." - <a href='/files/".$link."'>download</a></td></tr><tr><td width='200' border='1' bgcolor='#ffffff'>".$info."</td></tr></table>";
fwrite($fp, $insertcode);
fclose($fp);
?>
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Sun Nov 23, 2003 9:51 pm
i'd like to know how to make it o it does not overwrite the file, i want it so it just ads to it.
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Sun Nov 23, 2003 9:59 pm
change the w+ to a+
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Sun Nov 23, 2003 10:00 pm
Thanks a million, and trust me if i had a mill id give it to you;)
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Sun Nov 23, 2003 10:09 pm
lol no prob
i had that same problem last month, i was making a HTML editor for my client and my friend helped me w/it