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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    simple IF / ELSE not working properly

    I got overconfident and added in an IF/ELSE statement to my formhandler. However even if I dont enter an email value, and just click send, it doesn't get to the ELSE part, so basically tis not working!

    Can anyone see the error?


    if (isset($_POST['email'])) {

    $email=$_POST['email'];

    echo "The address " . $email . " has been added to the database.";

    $query = "INSERT INTO mailinglist VALUES ('','$email',NOW())";
    mysql_query($query);

    mysql_close();

    echo "Thank you for joining our mailing list.<p>";

    }

    else {

    echo "You did not enter an email address!";
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Its because $_POST['email'] exists, its just empty.
    Instead of:
    PHP Code:
    if (isset($_POST['email'])) 
    use:
    PHP Code:
    if (!empty($_POST['email'])) 
    and it should work fine for you.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup, works now, thanks!


  •  

    Posting Permissions

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