I am trying to write a email address to a file. the user enters there email addy and submits which brings them to the following code. however im unable to figureout what im doing wrong to write to the file. any ideas?

$myfile = file("data/mylist.lst");
$fh = fopen("data/mylist.lst","w");
for ($index=0; $index < count($myfile); $index++)
{ if ($Email != chop($myfile[$index])) {fputs($fh,$myfile[$index]);}
} fputs($fh,$Email."\n"); fclose($myfile); ?>

<a href="../index.php">Home</a>. </body></html>

If you open a file using "w" mode it truncates the file (thus making it 0 in length) so your code wont even execute. Try opening the file in "a" or "a+" mode. (a is writing, a+ is reading and writing)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.