Hello all, I have set up a form that updates two text files, subscribe.txt and unsubscribe.txt, when the user inputs their email address to the form, checks subscribe or unsubscribe, and submits it.
The php script is
PHP Code:
<?php
$Name = $_POST["name"];
$EmailAd = $_POST["email"];
$Subs = $_POST["sub_or_unsub"];
if ($Subs=="Sub"){
$fp = fopen("subscribe.txt", "a") or die("Error creating/writing to new file.");
fwrite($fp, "\r\n" . $Name);
fwrite($fp, "\r\n" . $EmailAd);
fclose($fp);
echo "<font class='main_text'>Thank you for subscribing!</font>";
}else if ($Subs=="Unsub"){
$fp = fopen("unsubscribe.txt", "a") or die("Error creating/writing to new file.");
fwrite($fp, "\r\n" . $Name);
fwrite($fp, "\r\n" . $EmailAd);
fclose($fp);
echo "<font class='main_text'>Thank you for unsubscribing!</font>";
}
?>
The actual form is in a very crude layout currently and is:
Quote:
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font class="main_text">To recieve special offers from local businesses submit your <br>
e-mail address:</font></td>
</tr>
<tr>
<td><font class="main_text">Name: </font><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td><font class="main_text">E-mail: </font><input type="text" name="email" size="19"></td>
</tr>
<tr>
<td><input type="radio" name="sub_or_unsub" value="Sub" checked>
<span class="main_text">Subscribe</span></td>
</tr>
<tr>
<td><input type="radio" name="sub_or_unsub" value="Unsub">
<span class="main_text">Unsubscribe</span></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
|
I dont know how to integrate the php code with the form so that when a user clicks submit to subscribe the form will disappear and it will just say "Thankyou for Subscribing" in the space where the form used to exist, and vice versa for unsubsribing. I am experimenting but i keep getting various errors. (the php currently sits immediately before the html form on my webpage) If anyone can point out any flaws or suggestions that would be great.