Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-27-2005, 04:00 PM   PM User | #1
dysfunctionGazz
Regular Coder

 
Join Date: Jul 2002
Location: Brighton
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
dysfunctionGazz is an unknown quantity at this point
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!";
}
dysfunctionGazz is offline   Reply With Quote
Old 04-27-2005, 04:03 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 04-27-2005, 05:34 PM   PM User | #3
dysfunctionGazz
Regular Coder

 
Join Date: Jul 2002
Location: Brighton
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
dysfunctionGazz is an unknown quantity at this point
Yup, works now, thanks!
dysfunctionGazz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:40 PM.


Advertisement
Log in to turn off these ads.