...

View Full Version : simple IF / ELSE not working properly



dysfunctionGazz
04-27-2005, 04:00 PM
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!";
}

Fou-Lu
04-27-2005, 04:03 PM
Its because $_POST['email'] exists, its just empty.
Instead of:


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

use:


if (!empty($_POST['email']))

and it should work fine for you.

dysfunctionGazz
04-27-2005, 05:34 PM
Yup, works now, thanks! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum