On my website I have a form for adding an email address to a mailing list. I don't really have a mailing list, I just want the email address the user enters written to a log file which is invisible to the user.
As it is now, you enter in your email address and click submit. The form action points to emailadd.php which just shows the user a plain old screen of text saying "Your email address has been added, thank you". It also writes to a log file which is just a blank (until written to) HTML file that only I know about, but I'm having trouble sending their post data to the log file. I know I have everything configured right as far as the form goes. If I simply insert echo $_POST['email']; at the top of emailadd.php, it shows the post data fine on the thank you screen. So emailadd.php is recieving and recognizing the post data no problem, but for some reason it won't pass it on to the log file. When I try to have it written to the log file it just comes out blank.
The log file itself is being accessed properly, because upon each submission the word Email: is printed in the log, just as intended, but after Email: is supposed to appear the post data which would be the user's email address, and nothing shows up.
Any advice?
How can I have post data written to a log file?
Moderator: General Moderators
Here is the code for the writing of the log file (emailadd.php). I'm assuming the problem is somewhere in here rather than in the form code.
The result is the word "Email:" being printed in the log file and nothing else.
Code: Select all
<?php
$fw=fopen("email_list.html","a");
$fdata=sprintf("<b>Email:</B> ",$_POST['email'],"<BR>","\n");
$logadd=fputs($fw,$fdata);
fclose($fw);
?>Try this
There's no real reason to use sprintf here, might as well just use:
Code: Select all
<?php
$fw = fopen("email_list.html","a");
$fdata = sprintf("<b>Email:</B> %s %s %s",$_POST['email'],"<BR>","\n");
$logadd = fputs($fw,$fdata);
fclose($fw);
?>Code: Select all
$fdata = "<B>Email:</B> ".$_POST["email"]." <BR>";