I'm very new to PHP and when trying to pass a value from a form field I keep getting an udefined varialbe error. Here's a snippet of code.
The form;
Here is the php page the form posts too;
these are the errors I get;
Notice: Undefined variable: email in c:\inetpub\ on line 6
Notice: Undefined variable: email in c:\inetpub\ on line 10
Thank you for joining the mailing list, you should recieve a confirmation email from us within 5 minutes and you will get an email from us every week, blah
Notice: Undefined variable: email in c:\inetpub\ on line 14
Notice: Undefined variable: name in c:\inetpub\ on line 19
Notice: Undefined variable: email in c:\inetpub\ on line 21
//this error I'll deal with later unless someone can help
Warning: Bad Message destination in c:\inetpub\ on line 24
I got this code from and followed the instructions as closely as I could.I'm using IIS for my server and the instructions are for Apache.I'm trying to teach myself PHP by checking other peoples code. No matter what code I try when passing a value from a form to a PHP page I get the undefined variable error. I am used to coding with ASP and use request.form method for transfering values. As I've said I'm real new to php and can't seem to get a value from a form in this language. Can anyone help me with the solution of how to do this in PHP?
All help would be greatly appreciated.
The form;
Code:
<form action="add.php" method="post">
<table border="1" bordercolor="#000000"
bordercolordark="#000000" bordercolorlight="#000000">
<tr>
<td bgcolor="#35C0D0"><p align="left"><font size="5">Join
the mailing list</font></p>
</td>
</tr>
<tr>
<td bgcolor="#008080">NAME:<font size="4"><input
type="text" size="20" name="name"></font></td>
</tr>
<tr>
<td bgcolor="#008080">EMAIL:<font size="4"><input
type="text" size="20" name="email"></font></td>
</tr>
<tr>
<td bgcolor="#008080"><p align="right"><INPUT TYPE="image" SRC="ok.gif"></p>
</td>
</tr>
</table>
<p> </p>
</form>
Code:
<?php
$filename = "members.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
if(strstr($contents,$email)) {
print "Your already subscribed to this mailing list.";
}
else {
echo "Thank you $email for joining the mailing list, you should recieve a confirmation email from us within 5 minutes and you will get an email from us every week, blah";
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);
//I'm assuming that X-Mailer is a module I'll have to load
//At this point all I want to do is fget the values from
//the form
mail("$email", "Compustorm Mailing List", "This email is to confirm that you have been added to the compustorm mailing list.",
"From: MailList@compustorm.com\r\n"
."Reply-To: DONTEMAILBACK@compustorm.com\r\n"
."X-Mailer: PHP/" . phpversion());
}
?>
Notice: Undefined variable: email in c:\inetpub\ on line 6
Notice: Undefined variable: email in c:\inetpub\ on line 10
Thank you for joining the mailing list, you should recieve a confirmation email from us within 5 minutes and you will get an email from us every week, blah
Notice: Undefined variable: email in c:\inetpub\ on line 14
Notice: Undefined variable: name in c:\inetpub\ on line 19
Notice: Undefined variable: email in c:\inetpub\ on line 21
//this error I'll deal with later unless someone can help
Warning: Bad Message destination in c:\inetpub\ on line 24
I got this code from and followed the instructions as closely as I could.I'm using IIS for my server and the instructions are for Apache.I'm trying to teach myself PHP by checking other peoples code. No matter what code I try when passing a value from a form to a PHP page I get the undefined variable error. I am used to coding with ASP and use request.form method for transfering values. As I've said I'm real new to php and can't seem to get a value from a form in this language. Can anyone help me with the solution of how to do this in PHP?
All help would be greatly appreciated.