Page 1 of 14 12311 ... LastLast
Results 1 to 10 of 137

Thread: javascript? php? simple mailing list database?

  1. #1
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default javascript? php? simple mailing list database?

    im trying to find a simple script i can embed in an html form on my website so that a user can enter their email address to receive updates/invites, and when they click submit it will write the text they input into a text file on the sever, with each entry separated by a semicolon... so that everytime i add new work to my site, i can copy/paste the most recent mailing list directly into my mail client... like so:

    user@domain.com; user1@domain1.com; user2@domain2.com; etc

    is this possible? anyone have a code that does this or, if not, advice on how to code this myself? much appreciated.

    also, if it were possible to have the code check the database for duplicates, that would be helpful.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sure. that's quite easy.

    My comments script could be used as a base for this.
    That's in a couple threads floating around.

    doing the list is easy.... but checking for duplicates is a bit harder. Actually.... hmm... no, I guess it isn't.


    I'll write it up for you now.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Include the following php code at the VERY TOP of your page:
    PHP Code:
    <?php
    if ($email stripslashes($_POST['email'])) {
        
    $filename "emails.phplist";
        
    $filecontents = @file_get_contents($filename);
        if (
    $_POST['choice'] == "join") {
            if (
    strpos($filecontents) != "") break; 
            if (
    strlen($filecontents) > 0$comma ", ";
            
    $add $comma.$email;
            
    $emails $filecontents.$add;
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$emails);
            @
    fclose($file);
            
    $message "Your email was added to the mailing list.".
            
    "<br>Redirecting to the last page.";
        }
        elseif (
    $_POST['choice'] == "leave") {
            
    $edited str_replace($email,"",$filecontents);
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$edited);
            @
    fclose($file);
            
    $message "Your email was removed from the mailing list.".
            
    "<br>Redirecting to the last page.";
            }
        }
    if (
    $message != "") die("<html><head>".
    "<meta http-equiv=\"refresh\" content=\"3;url=\">".
    "</head><body>".$message."</body></html>");
    ?>
    <!-- YOUR HTML GOES BELOW HERE -->
    HTML Code:
    <!-- THEN JUST INCLUDE THE FOLLOWING SOMEWHERE IN YOUR BODY SECTION -->
    <form action="" method="post">
    Join our newsletter!<br>
    Email: <input type="text" name="email"><br>
    <select name="choice">
    <option value="join">Join</option>
    <option value="leave">Leave</option>
    </select>mailing list.<br>
    <input type="Submit" value="Go!">
    </form>

    Random note... after writing this, i've decided there must be a better way to write scripts than in the post window


    Ok... gotta run. This should work, but I haven't tested it yet...
    I'll check back when I get a chance.

    EDIT: Fixed two errors in the code.
    Last edited by djr33; 06-02-2006 at 05:51 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    hey thanks, can you dumb it down even more for me though?

    1. what url goes in the <form action="(url)" method="post"> tag?
    2. does the script autocreate a text file called "emails.phplist" or do i need to create one? if so, how do i do that and do i store it in the same directory folder?
    3. the php script is showing up on the html page, why is that? should i make the script external and link to that url in the form action??

    thanks again, sorry if these are dumb questions.

  5. #5
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    oh, and

    4. where do i make the url for the redirect page?

  6. #6
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    if you go to moscarda.com/php you can view source and see what im trying to do.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    AHHHH! just wrote a long reply.. and it didn't get saved... well... here's the short version:

    1. The form action is the current page. "" should work for that, or you could use the currentpage.php in there.

    I made a mistake... change the last part of the php to this:
    Code:
    if ($message != "") die("<html><head>".
    "<meta http-equiv=\"refresh\" content=\"3;url=\">".
    "</head><body>$message</body></html>");
    Note that the "3" means 3 seconds. Use what you want.
    IF you want 0, like to not have a message, use comments to disable that entire thing, so you can still get it back (don't delete), but it won't do that... it'll just display your original page:
    Code:
    /*if ($message != "") die("<html><head>".
    "<meta http-equiv=\"refresh\" content=\"3;url=\">".
    "</head><body>$message</body></html>");*/
    4. The URL for the redirect needs to be the CURRENT page as well. I think leaving it blank would default to that, but it might send the form again (like refresh does sometimes) and would just do an endless loop of submitting, refreshing.... so.... see what happens, and add your currentpage.php url in if it seems to matter.


    2. If autocreates it.
    You can control filename at the top by changing that. Whatever extension is fine... just use notepad to open in the end. If you WANT to be able to view in your browser, you could even use .htm.... but that would make it easily publicly accessible, if they could find the url of the file. Not that you'd ever give that out, so it's probably ok.
    It is the SAME directory. If you want another, use "directory/filename.ext".
    However, it will only create the FILE if it doesn't exist... YOU must create the directory.


    3. From the link you just posted, looks like it's working ok. I'll check that out now to see what's going on.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Looks like your page has a syntax error... says line 27, which, by the way it is above, is this line:
    "</head><body>$message</body></html>");

    I *think* it is that the $message isn't working. That should display the message.. the contents of the variable.
    The way around that is this:
    "</head><body>".$message."</body></html>");


    Try that.


    AND! You have put the php in a seperate page. It won't work.

    Actually... I guess it would... if you set the url of the form to that page and the url of the redirect to the index.

    But.... just put the php at the top of your index page and it won't do anything UNLESS someone has submitted the form. That's why the if is there.


    Your index should be:
    <?php mystuff here ?>
    <html>....your page stuff...<body>
    your body stuff
    <form myformhere></form>
    the rest of your body stuff
    the end of your code</html>


    Note: updating the codes above to fix the "3" error and this error.

    And oh yeah... you don't need the <!-- goes in body section --> comment for the form. Doesn't hurt, but not needed.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2005
    Location
    UK
    Posts
    159
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    okay i made the changes you mentioned, including putting the php in the same html file... it is still spitting out the php when you view the page...definatly not working correctly: check it out at http://moscarda.com/php ... plus, the when submitted, the form calls this error:

    Method Not Allowed
    The requested method POST is not allowed for the URL /php/index.html.

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yeah, you're using an html page, not a php page. Clearly, this won't work with php.

    Just rename index.html to index.php and it'll all work. I think.


    Since you just supplied the directory (/php/) I didn't see the extension of the index... or I would've caught it earlier. Sorry.



    As for the post method thing, I'm not sure why it says that. Fix the php extension, and we'll see where we are. I don't understand why that would be an error... sounds like its referring to the method="post" of the form, not the php code, as the only "post" stuff in there is variables.. not "methods". If it is related to having that in the form, but I don't really get it. html is interpreted by the browser, so your host couldn't be weird or anything... and your page isn't complex; nothing would be making that have anything in particular that would be an error.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •