I have a website where I have two text boxes for information entry. My "Submit" Button orders a PHP file to take the information in the two text boxes and copy/paste it into a text file named "Members.txt" The purpose is to take the information from the text boxes and create a mailing list. Now my problem is that I know the PHP file is calling for the text file because each time I hit submit, i can see on my ftp that the text file has been edited at the same time I try to submit to be apart of the list. In additon, the text file Is attempting to place the information into the text file as I can see that every time the "Submit" button is hit, the Text files entry lines are lower and lower. In otherwords a complete line is entered. but no text. And no, the text is not white. What am I doing wrong?
<h2>Join our Mailing List</h2>
<form method="post" action="add.php" name="signup">
<input type="hidden" name="pommo_signup" value="true" />
<table border="0" bordercolor="#000000"
bordercolordark="#000000" bordercolorlight="#000000">
<tr>
<td width="203" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> NAME: <font size="4">
<input name="name"
type="text" size="20" maxlength="100" />
</font></td>
</tr>
开发者_JAVA百科<tr>
<td height="26" bgcolor="#FFFFFF"> EMAIL: <font size="4">
<input name="email"
type="text" size="20" maxlength="100" />
</font></td>
</tr>
<tr>
<td height="31" bgcolor="#FFFFFF"><span style="text-align: left"></span><p align="middle">
<input type="image" src="ok.jpg" />
</p></td>
</tr>
</table>
</form>
THEN BELOW IS THE FORM THAT IS SUPPOSED TO ADD TO THE TEXT BOX.
<?php
$filename = "members.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
if(strstr($contents,$email)) {
print "You're already subscribed to this mailing list.";
}
else {
echo "Thank you $email for joining the mailing list";
if (!$save = fopen("members.txt","a")) {
exit;
}
fwrite($save,"$email\r\n");
fclose($save);
if (!$save = fopen("names.txt","a")) {
exit;
}
fwrite($save,"$name\r\n");
fclose($save);
mail("$email", "Fairview HiFi News Letter", "Welcome to the Fairview HiFi mailing list. Your exclusive source for product and promotional news and events.",
"From: Newsletter@FairviewHiFi.com\r\n"
."Reply-To: NOREPLY@FairviewHiFi.com\r\n"
."X-Mailer: PHP/" . phpversion());
}
?>
Use $_POST['email']
not $email
.
Your server has disabled register globals, which means that form inputs (and GET vars) aren't automatically avaliable in the form of $formFieldName
, so you have to use $_POST/GET/COOKIE/...
And don't change this setting, it's a huge security hole if you enable register globals.
Posted variables need to be referenced via $_POST
. So your email will be:
print $_POST["email"];
And not merely $email
. Additionally, since you're appending new lines, you might find a less-verbose solution to be appealing. See file_put_contents()
with the FILE_APPEND
flag:
<?php
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith\n";
// Append the contents of $person to the file named by $file.
file_put_contents($file, $person, FILE_APPEND);
?>
精彩评论