Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Need help with mailing list script.

    Hi Guys,

    I am wanting to create the simplest script possible but I cannot do it. I also cannot find any tutorial online which matches what I need. So I thought you helpful souls here could give me a hand.


    What I need

    I have a form with TWO fields.

    1. Name.
    2. Email Address.

    When the form submits it adds Name and Email address to a database called 'mailinglist'.

    Directly above the form I have two divs one is a red box and one is a greenbox. Obviously if they enter something incorrectly the div which is red will appear, or if they enter everything correctly then when they click submit it adds them to db and shows them the green div saying you have been added.

    Could anybody help me create this? I would really appreciate it. Whilst I understand the logic behind PHP and know what I need to do I cannot execute it.


    I look forward to the help.

    Cheers

    Dan
    Last edited by winnard2008; 04-29-2010 at 05:55 PM.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi Phil,

    Thanks again, will have a look into this tomorrow when I get chance.


    Cheers

  • #4
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Just to let you know.

    I found your snippet for the email form without email. Added it and it worked, except for once you hit submit it strips my css away from the page so all you see is like plain text with no styling.

    If you could assist with helping me make it so that it adds the success or alert part without losing the css that would great


    Dan

  • #5
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have narrowed the problem down to

    define return address part and also the header(location) part of the script which is causing me the problem.

    It is adding the msg to the url in the browser which has either a div class for success or an alert for errors added to the browser url rather than to the page itself.

  • #6
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Any ideas anyone?

  • #7
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    lets have a look at how you have used the code my friend and also the form used to send the data to.

    Regards, Phil

    p.s. if you are having problems with the script ( as i stated I didn't test that code fully sorry, will get around to it) comment out the header() and see what errors you are getting.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #8
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi Phil,

    The code works fine and submits the info entered into the form, it is just when you submit the form it strips away the css because it is showing a different address in the browser one which reads

    Code:
    http://localhost/rethink/index.php/?msg=%3Cdiv+class%3D%22alert%22%3E%3Cp%3EYour+Name+and+or+Email+Address+is+incorrect%2C+please+check+and+try+again.%3C%2Fp%3E%3C%2Fdiv%3E%3Cbr+%2F%3E%3Cbr+%2F%3E
    I have a page called form.php which has the following part of your script in

    PHP Code:
    <?PHP 
    define
    "SUBMIT_BUTTON_NAME"'submitted' );
    define"DB_SERVER"'localhost' );
    define"DB_USERNAME"'root' );
    define"DB_PASSWORD"'password' );
    define"DB_NAME"'rethink' );
    define"TABLE_NAME"'mailinglist' );
    define"RETURN_ADDRESS"'index.php' );
    define"MSG"'<div class="success"><p>Thanks! Your now in the loop.</p></div><br/><br />' );
    ?>
    I then have the index.php page which has the following php

    PHP Code:
    <?php
    include 'form.php';

    $master = array( 
        
    'input_name' => array( 
                              
    'name'
                              
    'email'
                        ), 
        
    'regex' => array( 
                         
    '',
                         
    '^[_a-z0-9\-]+(\.[_a-z0-9\-]+)*@[a-z0-9\-]+(\.[a-z0-9\-]+)*(\.[a-z]{2,3})$'
                         
                    ),
        
    'error' => array( 
                    
    '<div class="alert"><p>Your Name and or Email Address is incorrect, please check and try again.</p></div><br /><br />' 
        
                    
    ), 
        
    'db_col' => array( 
                          
    'NAME'
                          
    'EMAIL' 
                          
                    
    )
    );
    if( isset( 
    $_POST[SUBMIT_BUTTON_NAME] ) ) {
        
    $CON mysql_connectDB_SERVERDB_USERNAMEDB_PASSWORD ) or die( "Error: on line " __LINE__ " located at " __FILE__ " " .  mysql_error() );
        
    mysql_select_dbDB_NAME$CON );
        function 
    filter$data ) {
            
    $data trimhtmlentitiesmb_convert_encoding$data'HTML-ENTITIES'"UTF-8") ) ); 
            if ( 
    get_magic_quotes_gpc() ) { 
                
    $data stripslashes$data ); 
            } 
            
    $data mysql_real_escape_string$data ); 
            return 
    $data;
        }
        foreach( 
    $_POST as $key => $val ) {
            
    $post[$key] = $val;
            unset( 
    $_POST[$key] );
        }
        foreach( 
    $master['input_name'] as $key => $input_name ) {
            if( ! isset( 
    $post[$input_name] ) || empty( $post[$input_name] ) ) {
                
    $msg $master['error'][$key];
                break;
            }elseif( ! empty ( 
    $master['regex'][$key] ) && ! preg_match"#" $master['regex'][$key] . "#is"$post[$input_name] ) ) {
                
    $msg $master['error'][$key];
                break;    
            }
        }
        if( ! isset( 
    $msg ) ) {
            
    $col_str '';
            
    $val_str '';
            foreach( 
    $master['db_col'] as $key => $col_name ) {
                
    $col_str .= "`" $col_name "`, ";
                
    $val_str .= "'" $post[$master['input_name'][$key]] . "', ";
            }
            
    $insert_query "INSERT INTO `" TABLE_NAME "` ( " substr$col_str0, -) . " ) VALUES ( " substr$val_str0, -) . " )";
            
    mysql_query$insert_query$CON ) or die( "Error: on line " __LINE__ " located at " __FILE__ " " .  mysql_error() );
            
    $msg MSG;
        }
        
    mysql_close$CON );
        
    header"location: " RETURN_ADDRESS "/?msg=" urlencode$msg ) );
        exit();
    }
    ?>
    I then have the following form layout.

    Code:
    <form class="newsletter-form" method="post" action="index.php">
    		<?PHP 
    		if( isset( $_GET['msg'] ) ) {
        			echo $_GET['msg'];
    				}
    		?>
    		<p>Let us keep you in the know, with all our latest products and great monthly printing offers.</p><br />
    		<label>Name:</label><span class="info" title="Enter Your Name: EG John Doe"><img src="images/info.png" alt="Enter Your Name" /></span>		        <br />
    		<input class="text" type="text" name="name" size="30" maxlength="30" /><br /><br />
    		<label>Email:</label><span class="info" title="Enter Your Email. EG. example@hotmail.co.uk" ><img src="images/info.png" alt="Enter Your Email" /></span><br />
    		<input class="text" type="text" name="email" size="30" maxlength="100" /><br /><br />
    		<input type="image" class="signup" src="images/button2.png" name="submitted" />
    		<input type="hidden" name="submitted" value="TRUE" />
    		</form>
    In the form where it has the $_GET info is where I would like to display the Success MSG or the Array Errors in there respective DIVS.

  • #9
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Oh and by the way, when I comment out the header part it simply shows a white blank screen.

  • #10
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    thats good then! use

    PHP Code:
    <?PHP 
    if( isset( $_GET['msg'] ) ) {
        echo 
    urldecode($_GET['msg']);
    }
    ?>
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #11
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    That is resulting in the same stripped down page and putting the info in the url and not the divs in the form area.

    Here is a quick before and after submit images.

    Before Submit



    After Submit


    Can you see what I mean.

  • #12
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    give me a source code screen shot ( mainly the head section ) after you have posted. It seems as tho you are putting the result code in the wrong place... i think

    p.s. love the background and logo ( had a look at your site, shame it's under construction )
    Last edited by Phil Jackson; 04-29-2010 at 03:36 PM.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #13
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi Phil,

    Here is the source of the form once submitted. As you can see it is adding the div but putting \ in between and after the class.



    The head of the page after submit does not show anything.

    The page is currently under construction because I am working on it, hence the form. Glad you like the logo etc.

    Hopefully I will be nearly ready to get the site live once I have got your form working.

    Cheers

    Dan

  • #14
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    <?PHP 
    if( isset( $_GET['msg'] ) ) {
        echo 
    stripslashes(urldecode($_GET['msg']));
    }
    ?>
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #15
    Regular Coder
    Join Date
    Jul 2008
    Location
    Blackpool, UK
    Posts
    176
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi Phil,

    It is still not working. I think it is because it is adding the message to the url in the browser rather than just posting to itself.

    What do we need to change in order to get rid of the added info in the url input


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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