Subscribe/Unsubscribe form help

  • ecu33
  • Novice
  • Novice
  • ecu33
  • Posts: 28
  • Loc: Eastern US

Post 3+ Months Ago

I am trying to add a text box for the user to enter their email address so that when my webpage (in design now) is updated I can send them an email. Can anyone steer me to where I can find info on how to set this up. Thanks to everyone here! Your awesome!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

In the simplest form what you can do is write a php/cgi scripts that would take the email addresses input by the surfers and keep appending to a text file. Later when you are done with the site you just send them an email and notify using the cc or bcc feature for bulk mail from your regular email account. You will have to do it manually. This will work if you are expecting a small number of visitors and don't mind doing little manual work. Actually this would be quite easy. Since the text file can be written in the appropiate form so that you can just copy and paste all the email addresses at once. You just have check it once for accuracy. Lots of address validity checks can be built in already.

Or you can go with a full fledged newsletter or mailing list program. Many are available for free on the net. Do a search in the scriptsearch.com for newletter or mailing list. Here is one written with php.

http://www.scriptsearch.com/details/4203.html

Quote:
Description: PHP Mailing List has been designed to make the life of webmasters easier. This script collects the mail addresses of all who want to recieve your newsletter. It also provides automation of the unsubscribe process. PHP Mailing List works using MySQL database which provides a high performance of your web-server. PHP Mailing List is a cross-platform solution and will work under Linux, FreeBSD, Solaris, or Windows9x/NT/2000.


If you want to go with the first solution, I can write you a small script for that in php.
  • ecu33
  • Novice
  • Novice
  • ecu33
  • Posts: 28
  • Loc: Eastern US

Post 3+ Months Ago

the first solution would work great. I'm not expecting alot of addresses. I appreciate the help and the script.
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Kool then. The few basic things you must have are: a php enabled server, the page that will have the script must have .php extension, and your ability to change file permission. Let me know if you have them.
  • ecu33
  • Novice
  • Novice
  • ecu33
  • Posts: 28
  • Loc: Eastern US

Post 3+ Months Ago

Yes, I have all of those.
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Very nice. Give me some time then to get around to writing it.
  • ecu33
  • Novice
  • Novice
  • ecu33
  • Posts: 28
  • Loc: Eastern US

Post 3+ Months Ago

Thanx quantumcloud!
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Sorry about the delay.

Anyway, here it is. It takes two fields. Name and email.

a. The form inside a table below goes in the page where you want people to submit the info. You can change the look anyway you choose, just make sure the form and the field names inside the form are unchanged.

Code: [ Select ]
<form name="form" method="post" action="./mailsubmitted.php">
 <table width="300" border="0" align="center" cellpadding="0" cellspacing="3" bordercolor="#CCCCCC">
  <tr>
   <td align="right" valign="middle" bgcolor="#CCCCCC"><p>Name:</p></td>
   <td align="left" valign="middle" bgcolor="dddddd">
    <p>
     <input name="name" type="text" class="input" id="contactname2" size="10" maxlength="25">
   </p>    </td>
  </tr>
  <tr>
   <td align="right" valign="middle" bgcolor="#CCCCCC">
    <p>Email:</p></td>
   <td align="left" valign="middle" bgcolor="dddddd">
    <p>
     <input name="email" type="text" class="input" id="email" size="10" maxlength="25">
*    </p>    </td>
  </tr>
  <tr>
   <td width="65%" align="left" valign="middle">Please enter your name and email address
   to get notified when the site is updated. </td>
   <td align="center" valign="middle"><div align="center">
     <input type="submit" name="Submit" value="Submit" class="button">
   </div></td>
  </tr>
 </table>
 <p>&nbsp;</p>
</form>
  1. <form name="form" method="post" action="./mailsubmitted.php">
  2.  <table width="300" border="0" align="center" cellpadding="0" cellspacing="3" bordercolor="#CCCCCC">
  3.   <tr>
  4.    <td align="right" valign="middle" bgcolor="#CCCCCC"><p>Name:</p></td>
  5.    <td align="left" valign="middle" bgcolor="dddddd">
  6.     <p>
  7.      <input name="name" type="text" class="input" id="contactname2" size="10" maxlength="25">
  8.    </p>    </td>
  9.   </tr>
  10.   <tr>
  11.    <td align="right" valign="middle" bgcolor="#CCCCCC">
  12.     <p>Email:</p></td>
  13.    <td align="left" valign="middle" bgcolor="dddddd">
  14.     <p>
  15.      <input name="email" type="text" class="input" id="email" size="10" maxlength="25">
  16. *    </p>    </td>
  17.   </tr>
  18.   <tr>
  19.    <td width="65%" align="left" valign="middle">Please enter your name and email address
  20.    to get notified when the site is updated. </td>
  21.    <td align="center" valign="middle"><div align="center">
  22.      <input type="submit" name="Submit" value="Submit" class="button">
  23.    </div></td>
  24.   </tr>
  25.  </table>
  26.  <p>&nbsp;</p>
  27. </form>


b. The php code below goes to a page named mailsubmitted.php . This is where the user is redirected after submission. Create the layout anyway you choose according to your site theme. The php code below goes where you want to show the user the message about a successful submission or invalid email address. The name field is optional. The php code only checks for a valid email address in the form someone@somehost.com . If invalid the user can go back and enter the address again.

PHP Code: [ Select ]
<?php
 
   $what = true;
 
   $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
 
   if (!$chkemail) {
 
            echo "Please enter a valid email address in the form someone@somehost.com<br>
 
            Hit the browser's back button to go back and enter a valid email address.<br>";
 
            $what = false;
 
            }
 
   $formatted = $name." : ".$email;
 
   if ($what == true)
 
   {
 
   $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
 
   if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
   fwrite($fp, "$formatted \r\n");
 
   fclose($fp);
 
                echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
 
                }
 
?>
  1. <?php
  2.  
  3.    $what = true;
  4.  
  5.    $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
  6.  
  7.    if (!$chkemail) {
  8.  
  9.             echo "Please enter a valid email address in the form someone@somehost.com<br>
  10.  
  11.             Hit the browser's back button to go back and enter a valid email address.<br>";
  12.  
  13.             $what = false;
  14.  
  15.             }
  16.  
  17.    $formatted = $name." : ".$email;
  18.  
  19.    if ($what == true)
  20.  
  21.    {
  22.  
  23.    $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
  24.  
  25.    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  26.  
  27.    fwrite($fp, "$formatted \r\n");
  28.  
  29.    fclose($fp);
  30.  
  31.                 echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
  32.  
  33.                 }
  34.  
  35. ?>


c. Before you test it, make a txt file named maildata.txt or somethingelse.txt that you specify above in the code. As it is all files must be in the same directory. CHMOD the file permission to world writable. 766 or 777 whatever works in your server.

d. Now try and submit. To view the data download and open the text file. It should output something like this:

Quote:


Let me know if there is a problem. Also if you want the information to be formatted in any other way you find convenient, we can change it.
  • ecu33
  • Novice
  • Novice
  • ecu33
  • Posts: 28
  • Loc: Eastern US

Post 3+ Months Ago

I'm still working on getting the mailsubmitted.php file to load after hitting the submit button. Is there a way to make this form work?

Code: [ Select ]
<form>
<tr align=left><td><b>Enter Your E-mail</b><br><input name="email" type=text id="email" style="width:120px;" size=10 maxlength="25"></td></tr>
<tr align=left><td><input type=radio>&nbsp;<b>Subscribe</b><br></td></tr>
<tr align=left><td><input type=radio>&nbsp;<b>Un Subscribe</b><br></td></tr>
<tr align=center><td><input type="submit" name="Submit" value="Submit" class="button">
          <br></td></tr>
</form>
  1. <form>
  2. <tr align=left><td><b>Enter Your E-mail</b><br><input name="email" type=text id="email" style="width:120px;" size=10 maxlength="25"></td></tr>
  3. <tr align=left><td><input type=radio>&nbsp;<b>Subscribe</b><br></td></tr>
  4. <tr align=left><td><input type=radio>&nbsp;<b>Un Subscribe</b><br></td></tr>
  5. <tr align=center><td><input type="submit" name="Submit" value="Submit" class="button">
  6.           <br></td></tr>
  7. </form>
  • ecu33
  • Novice
  • Novice
  • ecu33
  • Posts: 28
  • Loc: Eastern US

Post 3+ Months Ago

Sorry, I am trying to post the code for the form but my newbie status is telling on me.
[/code][/quote]
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Alright, I sorta got your idea. Here is the modified codes. This will save the inputs like this:

Quote:
Subscribe : test@yahoo.com
Unsubscribe : test1@yahoo.com
Unsubscribe : test2@yahoo.com
Subscribe : test3@yahoo.com
Subscribe : test4@yahoo.com
Unsubscribe : test5@yahoo.com



Form code:

Code: [ Select ]
<form method="post" action="mailsubmitted.php">
<table>
<tr align=left><td><b>Enter Your E-mail</b><br><input name="email" type=text id="email" style="width:120px;" size=10 maxlength="25"></td></tr>
<tr align=left><td><input name="chk" type=radio value="sub" checked>
&nbsp;<b>Subscribe</b><br></td></tr>
<tr align=left><td><input name="chk" type=radio value="unsub">
&nbsp;<b>Un Subscribe</b><br></td></tr>
<tr align=center><td><input type="submit" name="Submit" value="Submit" class="button">
          <br></td></tr>
</table>
</form>
  1. <form method="post" action="mailsubmitted.php">
  2. <table>
  3. <tr align=left><td><b>Enter Your E-mail</b><br><input name="email" type=text id="email" style="width:120px;" size=10 maxlength="25"></td></tr>
  4. <tr align=left><td><input name="chk" type=radio value="sub" checked>
  5. &nbsp;<b>Subscribe</b><br></td></tr>
  6. <tr align=left><td><input name="chk" type=radio value="unsub">
  7. &nbsp;<b>Un Subscribe</b><br></td></tr>
  8. <tr align=center><td><input type="submit" name="Submit" value="Submit" class="button">
  9.           <br></td></tr>
  10. </table>
  11. </form>



Php code:

PHP Code: [ Select ]
<?php
 
   $what = true;
 
   $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
 
   if (!$chkemail) {
 
            echo "Please enter a valid email address in the form someone@somehost.com<br>
 
            Hit the browser's back button to go back and enter a valid email address.<br>";
 
            $what = false;
 
            }
 
   if ($chk == "sub") {
 
   $formatted = "Subscribe"." : ".$email;
 
   }
 
   else $formatted = "Unsubscribe"." : ".$email;
 
 
 
   if ($what == true)
 
   {
 
   $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
 
   if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
   fwrite($fp, "$formatted \r\n");
 
   fclose($fp);
 
   echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
 
   }
 
?>
  1. <?php
  2.  
  3.    $what = true;
  4.  
  5.    $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
  6.  
  7.    if (!$chkemail) {
  8.  
  9.             echo "Please enter a valid email address in the form someone@somehost.com<br>
  10.  
  11.             Hit the browser's back button to go back and enter a valid email address.<br>";
  12.  
  13.             $what = false;
  14.  
  15.             }
  16.  
  17.    if ($chk == "sub") {
  18.  
  19.    $formatted = "Subscribe"." : ".$email;
  20.  
  21.    }
  22.  
  23.    else $formatted = "Unsubscribe"." : ".$email;
  24.  
  25.  
  26.  
  27.    if ($what == true)
  28.  
  29.    {
  30.  
  31.    $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
  32.  
  33.    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  34.  
  35.    fwrite($fp, "$formatted \r\n");
  36.  
  37.    fclose($fp);
  38.  
  39.    echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
  40.  
  41.    }
  42.  
  43. ?>


What kind of problem with the mailsubmitted.php you are facing? Remember to CHMOD the text file, or it won't write to the file.
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

i tried that script..im running windows 2000 and apache 1.3

here is the url:

http://168.103.115.178/moontime.html

any help would be appreciated to get the script working :-( ..

-erik


Notice: Undefined variable: email in c:\program files\apache group\Apache\htdocs\mailsubmitted.php on line 3
Please enter a valid email address in the form someone@somehost.com
Hit the browser's back button to go back and enter a valid email address.

Notice: Undefined variable: chk in c:\program files\apache group\Apache\htdocs\mailsubmitted.php on line 9

Notice: Undefined variable: email in c:\program files\apache group\Apache\htdocs\mailsubmitted.php on line 12
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Hi GhettoPuNKkiD,

The error you are getting means that the email variable is ot being passed to the mailsubmitted.php . Most probably you changed the form's email field name.

Quote:
<input name="email" type=text id="email" style="width:120px;" size=10 maxlength="25">


Make sure the id="email" is intact. Along with other id names of the html form.

If that does not solve your problem, post the code you are using as it is with any kind of change you might have made. I will have a look.
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

well i am using the exact code as you posted to the other user (The latest one) ..and im still getting the error...

here is a new url:

http://168.103.115.178/moonlist.htm

thanks,
-GPk
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Well, I am as sure as humanly possible that the code is alright. In fact, it is so simple that there is nothing to be messed up here. It works fine in my machine.

On the other hand, if you are using the exact code, it means it has something to do with the difference in server configuration. I see that you are probably using your home cmputer as server. And I also assume that you installed apache on a windows machine. If that is so, the problem could be a bug in the php.

Quote:
FORM variables are not passed when php.ini-optimized is used for C:\WINNT\php.ini.

The workaround is to use php.ini-dist instead.

http://aspn.activestate.com/ASPN/Mail/M ... Dev/830341

Another reason can be that you are using a php version that is above 4.20 and it has register global off by default. If that is causing the problem, this code has to be rewritten. Can you check out the above solution, and if the register global is off? You can get this info by saving a php file as phpinfo.php in the root directory with the following code.
PHP Code: [ Select ]
<?php
 
 
 
phpinfo();
 
 
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. phpinfo();
  6.  
  7.  
  8.  
  9. ?>
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

register global is off...

i have installed php on an apache server on windows 2000 .yes.

anything else you need to know?
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Okay try this php code instead of the old one.

PHP Code: [ Select ]
  <?php
 
  $email = $HTTP_POST_VARS['email'];
 
  $chk =  $HTTP_POST_VARS['chk'];
 
  $sub = $HTTP_POST_VARS['sub'];
 
  $unsub = $HTTP_POST_VARS['unsub'];
 
     
 
    $what = true;
 
    $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
 
    if (!$chkemail) {
 
                echo "Please enter a valid email address in the form someone@somehost.com<br>
 
               Hit the browser's back button to go back and enter a valid email address.<br>";
 
                $what = false;
 
                }
 
    if ($chk == "sub") {
 
    $formatted = "Subscribe"." : ".$email;
 
    }
 
    else $formatted = "Unsubscribe"." : ".$email;
 
 
 
    if ($what == true)
 
    {
 
    $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
 
    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
    fwrite($fp, "$formatted \r\n");
 
    fclose($fp);
 
    echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
 
    }
 
 
 
?>
  1.   <?php
  2.  
  3.   $email = $HTTP_POST_VARS['email'];
  4.  
  5.   $chk =  $HTTP_POST_VARS['chk'];
  6.  
  7.   $sub = $HTTP_POST_VARS['sub'];
  8.  
  9.   $unsub = $HTTP_POST_VARS['unsub'];
  10.  
  11.      
  12.  
  13.     $what = true;
  14.  
  15.     $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
  16.  
  17.     if (!$chkemail) {
  18.  
  19.                 echo "Please enter a valid email address in the form someone@somehost.com<br>
  20.  
  21.                Hit the browser's back button to go back and enter a valid email address.<br>";
  22.  
  23.                 $what = false;
  24.  
  25.                 }
  26.  
  27.     if ($chk == "sub") {
  28.  
  29.     $formatted = "Subscribe"." : ".$email;
  30.  
  31.     }
  32.  
  33.     else $formatted = "Unsubscribe"." : ".$email;
  34.  
  35.  
  36.  
  37.     if ($what == true)
  38.  
  39.     {
  40.  
  41.     $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
  42.  
  43.     if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  44.  
  45.     fwrite($fp, "$formatted \r\n");
  46.  
  47.     fclose($fp);
  48.  
  49.     echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
  50.  
  51.     }
  52.  
  53.  
  54.  
  55. ?>
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

We've made progress, it's saving the emails now to the text file. Thanks a ton..but I'm getting this error after subscribing and unsubscribing..


Notice: Undefined index: sub in c:\program files\apache group\Apache\htdocs\list.php on line 4

Notice: Undefined index: unsub in c:\program files\apache group\Apache\htdocs\list.php on line 5
Thank you for entering your email address. We will get back to you as soon as we launch our new site.

Also could you just make it so it says the email address instead of "Subscribe : username@blah.com" ???

Also, one more thing: I just want it to delete the email address from the text file when the user selects unsubscribe....

AND when they subscribe add a line ... so it jus basically adds/deletes lines depending on whether they subscribe or unsubscribe..



Thanks a ton so far,
-Erik
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Oh ok. Sorry about that. Was not paying attention. Take these two lines out of the code. :oops:

PHP Code: [ Select ]
  $sub = $HTTP_POST_VARS['sub'];
 
  $unsub = $HTTP_POST_VARS['unsub'];
  1.   $sub = $HTTP_POST_VARS['sub'];
  2.  
  3.   $unsub = $HTTP_POST_VARS['unsub'];


We can take out the subscribe or unsubscribe part, but then there would not be a way to tell what the user wants to do. We could do it if we add more code to do what you want next. But that'd take me some time to write, which I do not have right now. I never worked with a more-then-simple flat file database before. Always work with mysql. I suggest you implement the current code. If I can sneak out some time, I will check out the implode feature of php (*crosses finger).
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

:P its cool..lemme know..when you have time!

-erik

thanks a lot tho...
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?php
 
if($_POST['submit']) {
 
$what = true;
 
$chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
 
 
 
if (!$chkemail) {
 
echo "Please enter a valid email address in the form
 
someone@somehost.com<br>
 
Hit the browser's back button to go back and enter a valid email
 
address.<br>";
 
$what = false;
 
}
 
 
 
if ($chk == "sub") {
 
   $formatted = "Subscribe"." : ".$email;
 
   $fp = fopen("./moon.txt", "a");
 
   if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
 
 
   fwrite($fp, "$formatted rn");
 
   fclose($fp);
 
   echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
 
}
 
 
 
else {
 
$formatted = "Subscribe"." : ".$email;
 
    $filename="moon.txt";
 
    $file=file($filename);
 
    for($i=0;$i<count($file);$i++)
 
    {
 
        if(trim($file[$i])!=$formatted)
 
            $writeString.=$file[$i];
 
        else
 
            $deleted=1;
 
    }
 
    $openF=fopen($filename,"w");
 
    fwrite($openF,$writeString);
 
    fclose($openF);
 
 
 
    if($deleted) echo "Sorry to see you go!";
 
    else echo "Couldn't delete.";
 
 
 
 
 
}
 
 
 
}
 
 
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. if($_POST['submit']) {
  5.  
  6. $what = true;
  7.  
  8. $chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
  9.  
  10.  
  11.  
  12. if (!$chkemail) {
  13.  
  14. echo "Please enter a valid email address in the form
  15.  
  16. someone@somehost.com<br>
  17.  
  18. Hit the browser's back button to go back and enter a valid email
  19.  
  20. address.<br>";
  21.  
  22. $what = false;
  23.  
  24. }
  25.  
  26.  
  27.  
  28. if ($chk == "sub") {
  29.  
  30.    $formatted = "Subscribe"." : ".$email;
  31.  
  32.    $fp = fopen("./moon.txt", "a");
  33.  
  34.    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  35.  
  36.  
  37.  
  38.    fwrite($fp, "$formatted rn");
  39.  
  40.    fclose($fp);
  41.  
  42.    echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
  43.  
  44. }
  45.  
  46.  
  47.  
  48. else {
  49.  
  50. $formatted = "Subscribe"." : ".$email;
  51.  
  52.     $filename="moon.txt";
  53.  
  54.     $file=file($filename);
  55.  
  56.     for($i=0;$i<count($file);$i++)
  57.  
  58.     {
  59.  
  60.         if(trim($file[$i])!=$formatted)
  61.  
  62.             $writeString.=$file[$i];
  63.  
  64.         else
  65.  
  66.             $deleted=1;
  67.  
  68.     }
  69.  
  70.     $openF=fopen($filename,"w");
  71.  
  72.     fwrite($openF,$writeString);
  73.  
  74.     fclose($openF);
  75.  
  76.  
  77.  
  78.     if($deleted) echo "Sorry to see you go!";
  79.  
  80.     else echo "Couldn't delete.";
  81.  
  82.  
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94. ?>
  95.  
  96.  


okay, so my friend worked this up, isn't working on the windows box..he uses unix..what do i need to replace for it to work on the windows box?

first error is when the script is at the main pagE:

Notice: Undefined index: submit in c:\program files\apache group\Apache\htdocs\moontime.php on line 2

when you subscribe you get this error:
Notice: Undefined variable: email in c:\program files\apache group\Apache\htdocs\moontime.php on line 4
Please enter a valid email address in the form someone@somehost.com
Hit the browser's back button to go back and enter a valid email address.

Notice: Undefined variable: chk in c:\program files\apache group\Apache\htdocs\moontime.php on line 14

Notice: Undefined variable: email in c:\program files\apache group\Apache\htdocs\moontime.php on line 25

Notice: Undefined variable: writeString in c:\program files\apache group\Apache\htdocs\moontime.php on line 36

Notice: Undefined variable: deleted in c:\program files\apache group\Apache\htdocs\moontime.php on line 39
Couldn't delete.
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

The error messages are the same kind as before. The form variables are not being passed to the php file, because the register global is turned off. You can solve all this kind of problems by editing the php.ini file from the server. Find where it says register_global = off and make it "on". It's kind of a security risk, they say, for big sites that have sensitive info. But normally it's quite fine. Anyway, presently you can solve it like before.

PHP Code: [ Select ]
<?php
 
 
 
$submit = $HTTP_POST_VARS['submit'];
 
$email = $HTTP_POST_VARS['email'];
 
$chk = $HTTP_POST_VARS['chk'];
 
$writeString = $HTTP_POST_VARS['writeString'];
 
$deleted = $HTTP_POST_VARS['deleted'];  
 
 
 
if($submit) {
 
$what = true;
 
$chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
 
 
 
if (!$chkemail) {
 
echo "Please enter a valid email address in the form
 
someone@somehost.com<br>
 
Hit the browser's back button to go back and enter a valid email
 
address.<br>";
 
$what = false;
 
}
 
 
 
if ($chk == "sub") {
 
    $formatted = "Subscribe"." : ".$email;
 
    $fp = fopen("./moon.txt", "a");
 
    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
 
 
    fwrite($fp, "$formatted rn");
 
    fclose($fp);
 
    echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
 
}
 
 
 
else {
 
$formatted = "Subscribe"." : ".$email;
 
    $filename="moon.txt";
 
    $file=file($filename);
 
    for($i=0;$i<count($file);$i++)
 
    {
 
        if(trim($file[$i])!=$formatted)
 
            $writeString.=$file[$i];
 
        else
 
            $deleted=1;
 
    }
 
    $openF=fopen($filename,"w");
 
    fwrite($openF,$writeString);
 
    fclose($openF);
 
 
 
    if($deleted) echo "Sorry to see you go!";
 
    else echo "Couldn't delete.";
 
 
 
 
 
}
 
 
 
}
 
 
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. $submit = $HTTP_POST_VARS['submit'];
  6.  
  7. $email = $HTTP_POST_VARS['email'];
  8.  
  9. $chk = $HTTP_POST_VARS['chk'];
  10.  
  11. $writeString = $HTTP_POST_VARS['writeString'];
  12.  
  13. $deleted = $HTTP_POST_VARS['deleted'];  
  14.  
  15.  
  16.  
  17. if($submit) {
  18.  
  19. $what = true;
  20.  
  21. $chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
  22.  
  23.  
  24.  
  25. if (!$chkemail) {
  26.  
  27. echo "Please enter a valid email address in the form
  28.  
  29. someone@somehost.com<br>
  30.  
  31. Hit the browser's back button to go back and enter a valid email
  32.  
  33. address.<br>";
  34.  
  35. $what = false;
  36.  
  37. }
  38.  
  39.  
  40.  
  41. if ($chk == "sub") {
  42.  
  43.     $formatted = "Subscribe"." : ".$email;
  44.  
  45.     $fp = fopen("./moon.txt", "a");
  46.  
  47.     if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  48.  
  49.  
  50.  
  51.     fwrite($fp, "$formatted rn");
  52.  
  53.     fclose($fp);
  54.  
  55.     echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
  56.  
  57. }
  58.  
  59.  
  60.  
  61. else {
  62.  
  63. $formatted = "Subscribe"." : ".$email;
  64.  
  65.     $filename="moon.txt";
  66.  
  67.     $file=file($filename);
  68.  
  69.     for($i=0;$i<count($file);$i++)
  70.  
  71.     {
  72.  
  73.         if(trim($file[$i])!=$formatted)
  74.  
  75.             $writeString.=$file[$i];
  76.  
  77.         else
  78.  
  79.             $deleted=1;
  80.  
  81.     }
  82.  
  83.     $openF=fopen($filename,"w");
  84.  
  85.     fwrite($openF,$writeString);
  86.  
  87.     fclose($openF);
  88.  
  89.  
  90.  
  91.     if($deleted) echo "Sorry to see you go!";
  92.  
  93.     else echo "Couldn't delete.";
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }
  100.  
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107. ?>


I have'nt tested it but this out to take care of the errors.
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

hello ..hello:

okay since we've last "spoken" i got the script to "subscribe" and "unsubscribe" ..however one error lurks.. about the passing of http variables from the html form.

here is the error i'm getting after unsubscribing:

Notice: Undefined variable: writeString in c:\program files\apache group\Apache\htdocs\erik\moontime\moontime.php on line 48
Sorry to see you go!

<hr>

here is the php source code:
PHP Code: [ Select ]
 
<?php
 
 
 
$submit = $HTTP_POST_VARS['submit'];
 
$email = $HTTP_POST_VARS['email'];
 
$chk = $HTTP_POST_VARS['chk'];
 
// $writeString = $HTTP_POST_VARS['writeString'];
 
// $deleted = $HTTP_POST_VARS['deleted'];
 
 
 
if($_POST['submit']) {
 
$what = true;
 
$chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
 
 
 
if (!$chkemail) {
 
echo "Please enter a valid email address in the form
 
someone@somehost.com<br>
 
Hit the browser's back button to go back and enter a valid email
 
address.<br>";
 
$what = false;
 
}
 
 
 
if ($chk == "sub") {
 
    $formatted = $email;
 
    $fp = fopen("./moon.txt", "a");
 
    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
 
 
    fwrite($fp, "$formatted\r\n");
 
    fclose($fp);
 
    echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
 
}
 
 
 
else {
 
$formatted = $email;
 
    $filename="moon.txt";
 
    $file=file($filename);
 
    for($i=0;$i<count($file);$i++)
 
    {
 
        if(trim($file[$i])!=$formatted)
 
            $writeString.=$file[$i];
 
        else
 
            $deleted=1;
 
    }
 
    $openF=fopen($filename,"w");
 
    fwrite($openF,$writeString);
 
    fclose($openF);
 
 
 
    if($deleted) echo "Sorry to see you go!";
 
    else echo "Unable to delete your e-mail address from the database.";
 
 
 
 
 
}
 
 
 
}
 
 
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. $submit = $HTTP_POST_VARS['submit'];
  7.  
  8. $email = $HTTP_POST_VARS['email'];
  9.  
  10. $chk = $HTTP_POST_VARS['chk'];
  11.  
  12. // $writeString = $HTTP_POST_VARS['writeString'];
  13.  
  14. // $deleted = $HTTP_POST_VARS['deleted'];
  15.  
  16.  
  17.  
  18. if($_POST['submit']) {
  19.  
  20. $what = true;
  21.  
  22. $chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
  23.  
  24.  
  25.  
  26. if (!$chkemail) {
  27.  
  28. echo "Please enter a valid email address in the form
  29.  
  30. someone@somehost.com<br>
  31.  
  32. Hit the browser's back button to go back and enter a valid email
  33.  
  34. address.<br>";
  35.  
  36. $what = false;
  37.  
  38. }
  39.  
  40.  
  41.  
  42. if ($chk == "sub") {
  43.  
  44.     $formatted = $email;
  45.  
  46.     $fp = fopen("./moon.txt", "a");
  47.  
  48.     if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  49.  
  50.  
  51.  
  52.     fwrite($fp, "$formatted\r\n");
  53.  
  54.     fclose($fp);
  55.  
  56.     echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
  57.  
  58. }
  59.  
  60.  
  61.  
  62. else {
  63.  
  64. $formatted = $email;
  65.  
  66.     $filename="moon.txt";
  67.  
  68.     $file=file($filename);
  69.  
  70.     for($i=0;$i<count($file);$i++)
  71.  
  72.     {
  73.  
  74.         if(trim($file[$i])!=$formatted)
  75.  
  76.             $writeString.=$file[$i];
  77.  
  78.         else
  79.  
  80.             $deleted=1;
  81.  
  82.     }
  83.  
  84.     $openF=fopen($filename,"w");
  85.  
  86.     fwrite($openF,$writeString);
  87.  
  88.     fclose($openF);
  89.  
  90.  
  91.  
  92.     if($deleted) echo "Sorry to see you go!";
  93.  
  94.     else echo "Unable to delete your e-mail address from the database.";
  95.  
  96.  
  97.  
  98.  
  99.  
  100. }
  101.  
  102.  
  103.  
  104. }
  105.  
  106.  
  107.  
  108. ?>
  109.  
  110.  


and finally here is the html code:

<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Moontime Pizza E-mail List</title>
</head><body>
<form method="post" action="moontime.php">
<table height="128" width="266">
<tr align=left><td height="34" width="260"><font face="Tahoma">Moontime Pizza
E-mail List</font></td></tr>
<tr align=left><td height="34" width="260"><font face="Tahoma"><b>
<font size="1">Enter Your E-mail</font></b><font size="1"><br><input name="email" type=text id="email" style="width:120px;" size=10 maxlength="25"></font></font></td></tr>
<tr align=left><td height="39" width="260"><font size="1" face="Tahoma"><input name="chk" type=radio value="sub" checked>
&nbsp;<b>Subscribe</b><br></font></td></tr>
<tr align=left><td height="12" width="260"><font size="1" face="Tahoma"><input name="chk" type=radio value="unsub">
&nbsp;<b>Unsubscribe</b><br></font></td></tr>
<tr align=center><td height="27" width="260"><input type="submit" name="submit" value="Submit" class="button">
<br></td></tr>
</table>
</form>
</body></html>
<hr>

okay, obviously the writestring vairiable isn't being passed..i don't even have one setup in the html..but the script works fine with it embed into the php other than that error about it being undefined..

also when you enter an email addy that isnt in the text file and you click unsubscribe you get this error:

Notice: Undefined variable: writeString in c:\program files\apache group\Apache\htdocs\erik\moontime\moontime.php on line 48

Notice: Undefined variable: deleted in c:\program files\apache group\Apache\htdocs\erik\moontime\moontime.php on line 51
Couldn't delete.

i commented it out..maybe it needs to be re-instated..help!!
any help.. would be appreciated.
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

hmm...glad that you took the time to reply.

I have tested the script with the following code and it worked fine in my machine.

PHP Code: [ Select ]
<?php
 
 
 
$submit = $HTTP_POST_VARS['submit'];
 
$email = $HTTP_POST_VARS['email'];
 
$chk = $HTTP_POST_VARS['chk'];
 
$writeString = $HTTP_POST_VARS['writeString'];
 
$deleted = $HTTP_POST_VARS['deleted'];  
 
 
 
if($submit) {
 
$what = true;
 
$chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
 
 
 
if (!$chkemail) {
 
echo "Please enter a valid email address in the form
 
someone@somehost.com<br>
 
Hit the browser's back button to go back and enter a valid email
 
address.<br>";
 
$what = false;
 
}
 
 
 
if ($chk == "sub") {
 
    $formatted = "Subscribe"." : ".$email;
 
    $fp = fopen("./moon.txt", "a");
 
    if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
 
 
 
    fwrite($fp, "$formatted \r\n");
 
    fclose($fp);
 
    echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
 
}
 
 
 
else {
 
$formatted = "Subscribe"." : ".$email;
 
    $filename="moon.txt";
 
    $file=file($filename);
 
    for($i=0;$i<count($file);$i++)
 
    {
 
        if(trim($file[$i])!=$formatted)
 
            $writeString.=$file[$i];
 
        else
 
            $deleted=1;
 
    }
 
    $openF=fopen($filename,"w");
 
    fwrite($openF,$writeString);
 
    fclose($openF);
 
 
 
    if($deleted) echo "Sorry to see you go!";
 
    else echo "Couldn't delete.";
 
 
 
 
 
}
 
 
 
}
 
 
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. $submit = $HTTP_POST_VARS['submit'];
  6.  
  7. $email = $HTTP_POST_VARS['email'];
  8.  
  9. $chk = $HTTP_POST_VARS['chk'];
  10.  
  11. $writeString = $HTTP_POST_VARS['writeString'];
  12.  
  13. $deleted = $HTTP_POST_VARS['deleted'];  
  14.  
  15.  
  16.  
  17. if($submit) {
  18.  
  19. $what = true;
  20.  
  21. $chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
  22.  
  23.  
  24.  
  25. if (!$chkemail) {
  26.  
  27. echo "Please enter a valid email address in the form
  28.  
  29. someone@somehost.com<br>
  30.  
  31. Hit the browser's back button to go back and enter a valid email
  32.  
  33. address.<br>";
  34.  
  35. $what = false;
  36.  
  37. }
  38.  
  39.  
  40.  
  41. if ($chk == "sub") {
  42.  
  43.     $formatted = "Subscribe"." : ".$email;
  44.  
  45.     $fp = fopen("./moon.txt", "a");
  46.  
  47.     if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
  48.  
  49.  
  50.  
  51.     fwrite($fp, "$formatted \r\n");
  52.  
  53.     fclose($fp);
  54.  
  55.     echo "Thanks for subscribing to the Moontime Pizza E-mail list!!";
  56.  
  57. }
  58.  
  59.  
  60.  
  61. else {
  62.  
  63. $formatted = "Subscribe"." : ".$email;
  64.  
  65.     $filename="moon.txt";
  66.  
  67.     $file=file($filename);
  68.  
  69.     for($i=0;$i<count($file);$i++)
  70.  
  71.     {
  72.  
  73.         if(trim($file[$i])!=$formatted)
  74.  
  75.             $writeString.=$file[$i];
  76.  
  77.         else
  78.  
  79.             $deleted=1;
  80.  
  81.     }
  82.  
  83.     $openF=fopen($filename,"w");
  84.  
  85.     fwrite($openF,$writeString);
  86.  
  87.     fclose($openF);
  88.  
  89.  
  90.  
  91.     if($deleted) echo "Sorry to see you go!";
  92.  
  93.     else echo "Couldn't delete.";
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }
  100.  
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107. ?>


Now one thing I noticed that causes problem is this line.

PHP Code: [ Select ]
fwrite($fp, "$formatted \r\n");


After you copy and paste the code in your file, make sure that this part appears exactly as it is showing here. With the space and back slashes in the right place. Copy pasting sometimes messes it up. So take a 2nd look and fix it manually if needed be.
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

okay, fixed that one problem..but here's the error im getting on my machine still when i "subscribe" and "unsubscribe"

Notice: Undefined index: deleted in c:\program files\apache group\Apache\htdocs\moontime\moontime.php on line 4

Notice: Undefined index: writeString in c:\program files\apache group\Apache\htdocs\moontime\moontime.php on line 7


i made an index.php for my index:
PHP Code: [ Select ]
 
<?php
 
echo '<HTML><HEAD>
 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
 
<title>Moontime Pizza E-mail List</title>
 
</head><body link="#FFFFFF" vlink="#000000" alink="#000000" text="#3366CC" bgcolor="#FFFFFF">
 
<form method="post" action="moontime.php">
 
<table height="1" width="316" align="center">
 
<tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
 <img border="0" src="mpel.png" width="34" height="260"></td>
 
 </tr>
 
<tr align=left><td height="1" width="509" bgcolor="#FFFFFF">&nbsp;<p>&nbsp;</p>
 
 <p>&nbsp;</p>
 
 <p>&nbsp;</p>
 
 <p><font face="Verdana"><b>
 
 <font size="2">Enter Your E-mail Address:</font></b></font><font face="Verdana" size="1"><b><input name="email" type=text id="email" size=25 maxlength="35"></b></font></p>
 
 <p><font size="1" face="Verdana"><b><input name="chk" type=radio value="sub" checked></b></font><font size="2" face="Verdana"><b>
 
 Subscribe&nbsp; </b></font><font size="1" face="Verdana"><b><input name="chk" type=radio value="unsub"></b></font><font size="2" face="Verdana"><b>
 
 &nbsp;Unsubscribe</b></font></p>
 
 <input TYPE="submit" VALUE="Submit" name="submit" STYLE="font-size:8pt; background-color:#3366CC; font-family:verdana; color:#ffffff" style="float: left">
 
 <p align="center">
 
 &nbsp;<p align="center">
 
 ';
 
  $file = "mtemails4u.txt";
 
  $lines = count(file($file));
 
  echo '<b><font size="1" face="Verdana" color="black">';
 
  echo "[$lines "; echo '<font face="Verdana"><b>
 
 <font size="1">subscribers]<br></font>';
 
  echo '&nbsp;<b><font size="1" color="#3366CC" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr></table></form>
 
</body></html>';
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. echo '<HTML><HEAD>
  5.  
  6. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  7.  
  8. <title>Moontime Pizza E-mail List</title>
  9.  
  10. </head><body link="#FFFFFF" vlink="#000000" alink="#000000" text="#3366CC" bgcolor="#FFFFFF">
  11.  
  12. <form method="post" action="moontime.php">
  13.  
  14. <table height="1" width="316" align="center">
  15.  
  16. <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  17.  
  18.  <img border="0" src="mpel.png" width="34" height="260"></td>
  19.  
  20.  </tr>
  21.  
  22. <tr align=left><td height="1" width="509" bgcolor="#FFFFFF">&nbsp;<p>&nbsp;</p>
  23.  
  24.  <p>&nbsp;</p>
  25.  
  26.  <p>&nbsp;</p>
  27.  
  28.  <p><font face="Verdana"><b>
  29.  
  30.  <font size="2">Enter Your E-mail Address:</font></b></font><font face="Verdana" size="1"><b><input name="email" type=text id="email" size=25 maxlength="35"></b></font></p>
  31.  
  32.  <p><font size="1" face="Verdana"><b><input name="chk" type=radio value="sub" checked></b></font><font size="2" face="Verdana"><b>
  33.  
  34.  Subscribe&nbsp; </b></font><font size="1" face="Verdana"><b><input name="chk" type=radio value="unsub"></b></font><font size="2" face="Verdana"><b>
  35.  
  36.  &nbsp;Unsubscribe</b></font></p>
  37.  
  38.  <input TYPE="submit" VALUE="Submit" name="submit" STYLE="font-size:8pt; background-color:#3366CC; font-family:verdana; color:#ffffff" style="float: left">
  39.  
  40.  <p align="center">
  41.  
  42.  &nbsp;<p align="center">
  43.  
  44.  ';
  45.  
  46.   $file = "mtemails4u.txt";
  47.  
  48.   $lines = count(file($file));
  49.  
  50.   echo '<b><font size="1" face="Verdana" color="black">';
  51.  
  52.   echo "[$lines "; echo '<font face="Verdana"><b>
  53.  
  54.  <font size="1">subscribers]<br></font>';
  55.  
  56.   echo '&nbsp;<b><font size="1" color="#3366CC" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr></table></form>
  57.  
  58. </body></html>';
  59.  
  60. ?>
  61.  
  62.  


and here is my main script:

PHP Code: [ Select ]
 
<?php
 
 
 
$chk = $HTTP_POST_VARS['chk'];
 
$deleted = $HTTP_POST_VARS['deleted'];
 
$email = $HTTP_POST_VARS['email'];
 
$submit = $HTTP_POST_VARS['submit'];
 
$writeString = $HTTP_POST_VARS['writeString'];
 
 
 
if($_POST['submit']) {
 
$what = true;
 
$chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
 
 
 
if (!$chkemail) {
 
echo '<table height="1" width="390" align="center">
 
<tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
 <img border="0" src="mpel.png" width="34" height="260"></td>
 
 </tr>
 
<tr align=left><td height="1" width="583" bgcolor="#FFFFFF"><b>
 
 <font face="Verdana" size="2">Your e-mail address appears to be invalid. Try
 
 again.</font></b><br><br><br>
 
 <p align="center">
 
 &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></b></td></tr>
 
</table>';
 
$what = false;
 
}
 
 
 
// subscribe
 
if ($chk == "sub") {
 
    $formatted = $email;
 
    $fp = fopen("./mtemails4u.txt", "a");
 
    if (!$fp) die ("Unable to open database.");
 
    fwrite($fp, "$formatted \r\n");
 
    fclose($fp);
 
    echo'
 
   <table height="1" width="316" align="center">
 
   <tr align=left>
 
   <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
       <img border="0" src="mpel.png" width="34" height="260">
 
   </td></tr>
 
   <tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
 
       <font face="Verdana" size="2">Successfully subscribed.</font></b><hr><br><br><br>
 
        <p align="center">
 
 &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br><br>
 
   </td></tr>
 
</table>';
 
}
 
// end subscribe
 
// unsubscribe
 
if ($chk == "unsub") {
 
$formatted = $email;
 
    $filename="./mtemails4u.txt";
 
    $file=file($filename);
 
    for($i=0;$i<count($file);$i++)
 
    {
 
        if(trim($file[$i])!=$formatted)
 
            $writeString.=$file[$i];
 
        else
 
            $deleted=1;
 
    }
 
    $openF=fopen($filename,"w");
 
    fwrite($openF,$writeString);
 
    fclose($openF);
 
 
 
    if($deleted)
 
    echo '<table height="1" width="316" align="center">
 
   <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
 <img border="0" src="mpel.png" width="34" height="260"></td>
 
 </tr>
 
<tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
 
 <font face="Verdana" size="2">Successfully un-subscribed.</font></b><hr><br><br><br>
 
  <p align="center">
 
 &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
 
 
 
</table>';
 
    else {
 
    echo '<table height="1" width="390" align="center">
 
   <tr align=left>
 
   <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
   <img border="0" src="mpel.png" width="34" height="260"></td>
 
   </tr>
 
   <tr align=left><td height="1" width="583" bgcolor="#FFFFFF">
 
   <p align="center">
 
   &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
 
         </table>';
 
 
 
}
 
 
 
}
 
}
 
// end unsubscribe
 
?>
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. $chk = $HTTP_POST_VARS['chk'];
  7.  
  8. $deleted = $HTTP_POST_VARS['deleted'];
  9.  
  10. $email = $HTTP_POST_VARS['email'];
  11.  
  12. $submit = $HTTP_POST_VARS['submit'];
  13.  
  14. $writeString = $HTTP_POST_VARS['writeString'];
  15.  
  16.  
  17.  
  18. if($_POST['submit']) {
  19.  
  20. $what = true;
  21.  
  22. $chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
  23.  
  24.  
  25.  
  26. if (!$chkemail) {
  27.  
  28. echo '<table height="1" width="390" align="center">
  29.  
  30. <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  31.  
  32.  <img border="0" src="mpel.png" width="34" height="260"></td>
  33.  
  34.  </tr>
  35.  
  36. <tr align=left><td height="1" width="583" bgcolor="#FFFFFF"><b>
  37.  
  38.  <font face="Verdana" size="2">Your e-mail address appears to be invalid. Try
  39.  
  40.  again.</font></b><br><br><br>
  41.  
  42.  <p align="center">
  43.  
  44.  &nbsp;<p align="center">
  45.  
  46.  <BR>
  47.  
  48.  <BR>
  49.  
  50.  <BR>
  51.  
  52.  <BR>
  53.  
  54.  <BR>
  55.  
  56.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></b></td></tr>
  57.  
  58. </table>';
  59.  
  60. $what = false;
  61.  
  62. }
  63.  
  64.  
  65.  
  66. // subscribe
  67.  
  68. if ($chk == "sub") {
  69.  
  70.     $formatted = $email;
  71.  
  72.     $fp = fopen("./mtemails4u.txt", "a");
  73.  
  74.     if (!$fp) die ("Unable to open database.");
  75.  
  76.     fwrite($fp, "$formatted \r\n");
  77.  
  78.     fclose($fp);
  79.  
  80.     echo'
  81.  
  82.    <table height="1" width="316" align="center">
  83.  
  84.    <tr align=left>
  85.  
  86.    <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  87.  
  88.        <img border="0" src="mpel.png" width="34" height="260">
  89.  
  90.    </td></tr>
  91.  
  92.    <tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
  93.  
  94.        <font face="Verdana" size="2">Successfully subscribed.</font></b><hr><br><br><br>
  95.  
  96.         <p align="center">
  97.  
  98.  &nbsp;<p align="center">
  99.  
  100.  <BR>
  101.  
  102.  <BR>
  103.  
  104.  <BR>
  105.  
  106.  <BR>
  107.  
  108.  <BR>
  109.  
  110.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br><br>
  111.  
  112.    </td></tr>
  113.  
  114. </table>';
  115.  
  116. }
  117.  
  118. // end subscribe
  119.  
  120. // unsubscribe
  121.  
  122. if ($chk == "unsub") {
  123.  
  124. $formatted = $email;
  125.  
  126.     $filename="./mtemails4u.txt";
  127.  
  128.     $file=file($filename);
  129.  
  130.     for($i=0;$i<count($file);$i++)
  131.  
  132.     {
  133.  
  134.         if(trim($file[$i])!=$formatted)
  135.  
  136.             $writeString.=$file[$i];
  137.  
  138.         else
  139.  
  140.             $deleted=1;
  141.  
  142.     }
  143.  
  144.     $openF=fopen($filename,"w");
  145.  
  146.     fwrite($openF,$writeString);
  147.  
  148.     fclose($openF);
  149.  
  150.  
  151.  
  152.     if($deleted)
  153.  
  154.     echo '<table height="1" width="316" align="center">
  155.  
  156.    <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  157.  
  158.  <img border="0" src="mpel.png" width="34" height="260"></td>
  159.  
  160.  </tr>
  161.  
  162. <tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
  163.  
  164.  <font face="Verdana" size="2">Successfully un-subscribed.</font></b><hr><br><br><br>
  165.  
  166.   <p align="center">
  167.  
  168.  &nbsp;<p align="center">
  169.  
  170.  <BR>
  171.  
  172.  <BR>
  173.  
  174.  <BR>
  175.  
  176.  <BR>
  177.  
  178.  <BR>
  179.  
  180.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
  181.  
  182.  
  183.  
  184. </table>';
  185.  
  186.     else {
  187.  
  188.     echo '<table height="1" width="390" align="center">
  189.  
  190.    <tr align=left>
  191.  
  192.    <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  193.  
  194.    <img border="0" src="mpel.png" width="34" height="260"></td>
  195.  
  196.    </tr>
  197.  
  198.    <tr align=left><td height="1" width="583" bgcolor="#FFFFFF">
  199.  
  200.    <p align="center">
  201.  
  202.    &nbsp;<p align="center">
  203.  
  204.  <BR>
  205.  
  206.  <BR>
  207.  
  208.  <BR>
  209.  
  210.  <BR>
  211.  
  212.  <BR>
  213.  
  214.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
  215.  
  216.          </table>';
  217.  
  218.  
  219.  
  220. }
  221.  
  222.  
  223.  
  224. }
  225.  
  226. }
  227.  
  228. // end unsubscribe
  229.  
  230. ?>


what could be giving me the errors? it subscribes fine and unsubscribes from the text file...its almost there :lol: :lol: :lol: [/php]
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?php
 
 
 
    $deleted = $HTTP_POST_VARS['deleted'];
 
 
 
    $writeString = $HTTP_POST_VARS['writeString'];
 
 
 
?>
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6.     $deleted = $HTTP_POST_VARS['deleted'];
  7.  
  8.  
  9.  
  10.     $writeString = $HTTP_POST_VARS['writeString'];
  11.  
  12.  
  13.  
  14. ?>


Do you have form elements called "deleted" and "writeString"? I can't see them. Basically, the undefined index refers to the 'deleted' index of $HTTP_POST_VARS. If there is no form element, no value gets posted and therefore no index.

HTH
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

PHP Code: [ Select ]
$submit = $HTTP_POST_VARS['submit'];
 
$email = $HTTP_POST_VARS['email'];
 
$chk = $HTTP_POST_VARS['chk'];
 
@$writeString = $HTTP_POST_VARS['writeString'];
 
@$deleted = $HTTP_POST_VARS['deleted'];
  1. $submit = $HTTP_POST_VARS['submit'];
  2.  
  3. $email = $HTTP_POST_VARS['email'];
  4.  
  5. $chk = $HTTP_POST_VARS['chk'];
  6.  
  7. @$writeString = $HTTP_POST_VARS['writeString'];
  8.  
  9. @$deleted = $HTTP_POST_VARS['deleted'];


Change it like this. Or just delete these two lines and see what happens.

PHP Code: [ Select ]
$writeString = $HTTP_POST_VARS['writeString'];
 
$deleted = $HTTP_POST_VARS['deleted'];
  1. $writeString = $HTTP_POST_VARS['writeString'];
  2.  
  3. $deleted = $HTTP_POST_VARS['deleted'];
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

quantum.. you rock.. hahaha..okay ..it all works now..without any errors..i've got a question.. when you subscribe, and you enter a single word (no email address) it gives you both statements "Your e-mail address appears to be invalid. Try again." and "Successfully subscribed." ..i just need it to say invalid..and not subscribe the user...thanks ..it also does it when you unsubscribe also.

-erik
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

Hmm... seems like your friend forgot to use the $what. Anyway, this ought to take care of that.

PHP Code: [ Select ]
<?php
 
 
 
$chk = $HTTP_POST_VARS['chk'];
 
$email = $HTTP_POST_VARS['email'];
 
$submit = $HTTP_POST_VARS['submit'];
 
//@$writeString = $HTTP_POST_VARS['writeString'];
 
//@$deleted = $HTTP_POST_VARS['deleted'];
 
 
 
$what = true;
 
$chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
 
 
 
if (!$chkemail) {
 
echo '<table height="1" width="390" align="center">
 
<tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
 <img border="0" src="mpel.png" width="34" height="260"></td>
 
 </tr>
 
<tr align=left><td height="1" width="583" bgcolor="#FFFFFF"><b>
 
 <font face="Verdana" size="2">Your e-mail address appears to be invalid. Try
 
 again.</font></b><br><br><br>
 
 <p align="center">
 
 &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></b></td></tr>
 
</table>';
 
$what = false;
 
}
 
 
 
if ($what == true)
 
{
 
 
 
// subscribe
 
if ($chk == "sub") {
 
    $formatted = $email;
 
    $fp = fopen("./mtemails4u.txt", "a");
 
    if (!$fp) die ("Unable to open database.");
 
    fwrite($fp, "$formatted \r\n");
 
    fclose($fp);
 
    echo'
 
   <table height="1" width="316" align="center">
 
   <tr align=left>
 
   <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
       <img border="0" src="mpel.png" width="34" height="260">
 
   </td></tr>
 
   <tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
 
       <font face="Verdana" size="2">Successfully subscribed.</font></b><hr><br><br><br>
 
        <p align="center">
 
 &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br><br>
 
   </td></tr>
 
</table>';
 
}
 
// end subscribe
 
// unsubscribe
 
if ($chk == "unsub") {
 
$formatted = $email;
 
    $filename="./mtemails4u.txt";
 
    $file=file($filename);
 
    for($i=0;$i<count($file);$i++)
 
    {
 
        if(trim($file[$i])!=$formatted)
 
            $writeString.=$file[$i];
 
        else
 
            $deleted=1;
 
    }
 
    $openF=fopen($filename,"w");
 
    fwrite($openF,$writeString);
 
    fclose($openF);
 
 
 
    if($deleted)
 
    echo '<table height="1" width="316" align="center">
 
   <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
 <img border="0" src="mpel.png" width="34" height="260"></td>
 
 </tr>
 
<tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
 
 <font face="Verdana" size="2">Successfully un-subscribed.</font></b><hr><br><br><br>
 
  <p align="center">
 
 &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
 
 
 
</table>';
 
    else {
 
    echo '<table height="1" width="390" align="center">
 
   <tr align=left>
 
   <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
 
   <img border="0" src="mpel.png" width="34" height="260"></td>
 
   </tr>
 
   <tr align=left><td height="1" width="583" bgcolor="#FFFFFF">
 
   <p align="center">
 
   &nbsp;<p align="center">
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <BR>
 
 <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
 
         </table>';
 
 
 
}
 
 
 
}
 
}
 
// end unsubscribe
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. $chk = $HTTP_POST_VARS['chk'];
  6.  
  7. $email = $HTTP_POST_VARS['email'];
  8.  
  9. $submit = $HTTP_POST_VARS['submit'];
  10.  
  11. //@$writeString = $HTTP_POST_VARS['writeString'];
  12.  
  13. //@$deleted = $HTTP_POST_VARS['deleted'];
  14.  
  15.  
  16.  
  17. $what = true;
  18.  
  19. $chkemail = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email);
  20.  
  21.  
  22.  
  23. if (!$chkemail) {
  24.  
  25. echo '<table height="1" width="390" align="center">
  26.  
  27. <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  28.  
  29.  <img border="0" src="mpel.png" width="34" height="260"></td>
  30.  
  31.  </tr>
  32.  
  33. <tr align=left><td height="1" width="583" bgcolor="#FFFFFF"><b>
  34.  
  35.  <font face="Verdana" size="2">Your e-mail address appears to be invalid. Try
  36.  
  37.  again.</font></b><br><br><br>
  38.  
  39.  <p align="center">
  40.  
  41.  &nbsp;<p align="center">
  42.  
  43.  <BR>
  44.  
  45.  <BR>
  46.  
  47.  <BR>
  48.  
  49.  <BR>
  50.  
  51.  <BR>
  52.  
  53.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></b></td></tr>
  54.  
  55. </table>';
  56.  
  57. $what = false;
  58.  
  59. }
  60.  
  61.  
  62.  
  63. if ($what == true)
  64.  
  65. {
  66.  
  67.  
  68.  
  69. // subscribe
  70.  
  71. if ($chk == "sub") {
  72.  
  73.     $formatted = $email;
  74.  
  75.     $fp = fopen("./mtemails4u.txt", "a");
  76.  
  77.     if (!$fp) die ("Unable to open database.");
  78.  
  79.     fwrite($fp, "$formatted \r\n");
  80.  
  81.     fclose($fp);
  82.  
  83.     echo'
  84.  
  85.    <table height="1" width="316" align="center">
  86.  
  87.    <tr align=left>
  88.  
  89.    <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  90.  
  91.        <img border="0" src="mpel.png" width="34" height="260">
  92.  
  93.    </td></tr>
  94.  
  95.    <tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
  96.  
  97.        <font face="Verdana" size="2">Successfully subscribed.</font></b><hr><br><br><br>
  98.  
  99.         <p align="center">
  100.  
  101.  &nbsp;<p align="center">
  102.  
  103.  <BR>
  104.  
  105.  <BR>
  106.  
  107.  <BR>
  108.  
  109.  <BR>
  110.  
  111.  <BR>
  112.  
  113.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br><br>
  114.  
  115.    </td></tr>
  116.  
  117. </table>';
  118.  
  119. }
  120.  
  121. // end subscribe
  122.  
  123. // unsubscribe
  124.  
  125. if ($chk == "unsub") {
  126.  
  127. $formatted = $email;
  128.  
  129.     $filename="./mtemails4u.txt";
  130.  
  131.     $file=file($filename);
  132.  
  133.     for($i=0;$i<count($file);$i++)
  134.  
  135.     {
  136.  
  137.         if(trim($file[$i])!=$formatted)
  138.  
  139.             $writeString.=$file[$i];
  140.  
  141.         else
  142.  
  143.             $deleted=1;
  144.  
  145.     }
  146.  
  147.     $openF=fopen($filename,"w");
  148.  
  149.     fwrite($openF,$writeString);
  150.  
  151.     fclose($openF);
  152.  
  153.  
  154.  
  155.     if($deleted)
  156.  
  157.     echo '<table height="1" width="316" align="center">
  158.  
  159.    <tr align=left><td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  160.  
  161.  <img border="0" src="mpel.png" width="34" height="260"></td>
  162.  
  163.  </tr>
  164.  
  165. <tr align=left><td height="1" width="509" bgcolor="#FFFFFF"><b>
  166.  
  167.  <font face="Verdana" size="2">Successfully un-subscribed.</font></b><hr><br><br><br>
  168.  
  169.   <p align="center">
  170.  
  171.  &nbsp;<p align="center">
  172.  
  173.  <BR>
  174.  
  175.  <BR>
  176.  
  177.  <BR>
  178.  
  179.  <BR>
  180.  
  181.  <BR>
  182.  
  183.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
  184.  
  185.  
  186.  
  187. </table>';
  188.  
  189.     else {
  190.  
  191.     echo '<table height="1" width="390" align="center">
  192.  
  193.    <tr align=left>
  194.  
  195.    <td height="1" width="61" rowspan="2" bgcolor="#FFFFFF">
  196.  
  197.    <img border="0" src="mpel.png" width="34" height="260"></td>
  198.  
  199.    </tr>
  200.  
  201.    <tr align=left><td height="1" width="583" bgcolor="#FFFFFF">
  202.  
  203.    <p align="center">
  204.  
  205.    &nbsp;<p align="center">
  206.  
  207.  <BR>
  208.  
  209.  <BR>
  210.  
  211.  <BR>
  212.  
  213.  <BR>
  214.  
  215.  <BR>
  216.  
  217.  <b><font size="1" face="Verdana">© 2004 GhettoPuNKkiD</font></b><br></td></tr>
  218.  
  219.          </table>';
  220.  
  221.  
  222.  
  223. }
  224.  
  225.  
  226.  
  227. }
  228.  
  229. }
  230.  
  231. // end unsubscribe
  232.  
  233. ?>
  • GhettoPuNKkiD
  • Novice
  • Novice
  • GhettoPuNKkiD
  • Posts: 20

Post 3+ Months Ago

it's fixed! it works! i've implemented some things too..but to you quantum, i am grateful for your help...thanks so much... :oops: take care and such..

-erik
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 31 posts
  • Users browsing this forum: monica660 and 51 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.