hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : php problem with my mailing list
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

php problem with my mailing list

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-18-2005, 09:49 AM
Davey Gale Davey Gale is offline
Junior Guru Wannabe
 
Join Date: Aug 2004
Posts: 51

php problem with my mailing list


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:&nbsp;</font><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td><font class="main_text">E-mail:&nbsp;</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.

Reply With Quote


Sponsored Links
  #2  
Old 01-18-2005, 06:26 PM
xelav xelav is offline
Junior Guru
 
Join Date: Jul 2003
Posts: 235
what errors have you got? from first view should work

__________________
HostNodeList Web Host Directory, DEV.INTOEX.COM - products for online business

Experienced web-developer | PHP | Smarty | Zend | Databases | Graphic design - looking for long-time relationship

Reply With Quote
  #3  
Old 01-19-2005, 03:42 AM
Burhan Burhan is offline
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,100
Try this instead :

PHP Code:
<?php 
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
   
$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>";

}

} else {
?>
<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>
<?php ?>

__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

Reply With Quote
Sponsored Links
  #4  
Old 01-20-2005, 06:29 AM
Davey Gale Davey Gale is offline
Junior Guru Wannabe
 
Join Date: Aug 2004
Posts: 51
fyrestrtr, thankyou so much for that, works like a charm!!

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Pingdom Talks Top Web Hosting Cities and Countries Web Hosting News 2013-03-27 18:49:54
Web Hosts, IT Services Firms Make Inc 5000 Fastest Growing Companies Web Hosting News 2012-09-19 16:45:40
Students Contribute to Joomla through Google Summer of Code Program Web Hosting News 2012-05-08 15:22:35
Why you should get on the blogging bandwagon Blog 2011-11-03 16:26:00
Web Hosts Climb Inc. 5000 List of Fastest-Growing US Companies for 2011 Web Hosting News 2011-08-23 20:52:20


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?