Page 1 of 1

problem with $insertcode

Posted: Sun Nov 23, 2003 9:39 pm
by dull1554
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);

?>

Posted: Sun Nov 23, 2003 9:51 pm
by dull1554
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.

Posted: Sun Nov 23, 2003 9:59 pm
by d3ad1ysp0rk
change the w+ to a+ ;)

Posted: Sun Nov 23, 2003 10:00 pm
by dull1554
Thanks a million, and trust me if i had a mill id give it to you;)

Posted: Sun Nov 23, 2003 10:09 pm
by d3ad1ysp0rk
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