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.
Results 1 to 8 of 8

Thread: Redirect

  1. #1
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Redirect

    I'm trying to make this script to show the form when you first visit it, then when you submit it it does the things under action=subscribe or action=unsubscribe. Not working however. Ideas?

    PHP Code:
                $act = $_POST['action'];
                // THIS IS WHAT THE SCRIPT SHOULD DO IF subscribe IS SELECTED AND SUBMITTED THROUGH THE FORM
                if ( $act == "subscribe" ) {
                    // setting variables
                    $email = $_POST[email];
                    // inserting values into database
                    $query = "SELECT email FROM newsletter WHERE email = '$email'";
                        $result = mysql_query($query);
                        if(mysql_num_rows($result) != 0) {
                        print "<FONT>Your email address already exist in our database.</FONT>";
                    } else {
                    $sql = "INSERT INTO `newsletter` (`id`, `email`) VALUES ('', '$email')";
                        $result = mysql_query($sql) or die ("Not working try again");
                        if($result) { 
                        print "<FONT>You have been added to our Mailing List.</FONT>";
                    }
                    }
                }
                // THIS IS WHAT THE SCRIPT SHOULD DO IF unsubscribe IS SELECTED AND SUBMITTED THROUGH THE FORM
                elseif ( $act == "unsubscribe" ) {
                    $query = "SELECT email FROM newsletter WHERE email = '$_POST[email]'";
                    $result = mysql_query($query);
                    if(mysql_num_rows($result) == 0) {
                        print "<FONT>Your Email doesnot exist in our Database.</FONT>";
                    } else {
                        $sql = "DELETE FROM `newsletter` WHERE email='$_POST[email]'"; 
                        $result = mysql_query($sql) or die ("Not working try again"); 
                        if($result) {
                        print "<FONT>Your Email address has been removed successfully.</FONT>";
                    }
                }
                // THIS IS THE FORM THAT SHOULD BE SHOWING WHEN YOU FIRST GO TO THE PAGE
                else {
                    echo "<FORM NAME=\"newsletter\" ID=\"newsletter\" METHOD=\"post\" ACTION=\"<?php echo $PHP_SELF?>\">\n";
                    echo "    <FONT CLASS=\"f2\">SUBSCRIBE TO NEWSLETTER</FONT>\n";
                    echo "    <TABLE BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\">\n";
                    echo "        <TR>\n";
                    echo "            <TD ALIGN=\"right\" VALIGN=\"top\">\n";
                    echo "                <INPUT TYPE=\"text\" NAME=\"email\" SIZE=\"16\" MAXLENGTH=\"70\" VALUE=\"&nbsp;your@email.here\" CLASS=\"formstyle\" OnFocus=\"javascript:this.select()\">\n";
                    echo "            </TD>\n";
                    echo "            <TD ALIGN=\"left\" VALIGN=\"top\">\n";
                    echo "                <INPUT TYPE=\"image\" SRC=\"pics/go.gif\" NAME=\"submit\" VALUE=\"&nbsp;GO&nbsp;\" ALT=\"GO\" CLASS=\"submitstyle\">\n";
                    echo "            </TD>\n";
                    echo "        </TR>\n";
                    echo "        <TR>\n";
                    echo "            <TD COLSPAN=\"2\" ALIGN=\"center\" VALIGN=\"top\">\n";
                    echo "                <INPUT TYPE=\"radio\" NAME=\"action\" VALUE=\"subscribe\" CHECKED><FONT>Subscribe</FONT><BR>\n";
                    echo "                <INPUT TYPE=\"radio\" NAME=\"action\" VALUE=\"unsubscribe\"><FONT>Unsubscribe</FONT>\n";
                    echo "            </TD>\n";
                    echo "        </TR>\n";
                    echo "    </TABLE>\n";
                    echo "</FORM>\n";
                }
    Last edited by Noumenon; 02-09-2006 at 08:07 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    UK
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you be a bit more specific than "it's not working" is there an error?

  • #3
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nothing is shown when first entering the page.
    The form should be showing, it's not.

    After that, when submitting the form it should do either the subcribe part or unsubscribe.

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are missing a }

    If you are not getting a parse error then check your error reporting

    PHP Code:
    print "<FONT>Your Email address has been removed successfully.</FONT>";
                           }
                    }
                } 

  • #5
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx!

    I fixed that, plus changed
    PHP Code:
    echo "<FORM NAME=\"newsletter\" ID=\"newsletter\" METHOD=\"post\" ACTION=\"<?php echo $PHP_SELF?>\">\n";
    to

    PHP Code:
    echo "<FORM NAME=\"newsletter\" ID=\"newsletter\" METHOD=\"post\" ACTION=\"newsletter.php\">\n"
    it works now

  • #6
    Regular Coder
    Join Date
    Jul 2005
    Location
    LA, California
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    a } is usually the first reason a page turns up blank if you have php errors turned off, otherwise if they were on you would get an error message
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    There are 3 kinds of ppl those who can count and those who cant
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Script-Megafest.com Coming Oh so very soon

  • #7
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok. don't have much control over that since I'm not running my own server.

  • #8
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://uk.php.net/error_reporting

    You can add the code to your page(s)
    PHP Code:
    // Report all PHP errors (bitwise 63 may be used in PHP 3)
    error_reporting(E_ALL);

    // Same as error_reporting(E_ALL);
    ini_set('error_reporting'E_ALL); 


  •  

    Posting Permissions

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