You don't actually need to use both isset
and empty
, because empty
already does it.
No warning is generated if the variable does not exist. That means
empty() is essentially the concise equivalent to !isset($var) || $var
== false.
More details are here:
http://php.net/manual/en/function.empty.php
So your code could look this way, for example:
if (empty(trim($_POST['email']))) {
echo "Email cannot be empty!\n";
// you should add return or raise exception here
// or even exit
exit;
}
$email = trim($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Your email {$email} is invalid\n";
// you should add return or raise exception here
// or even exit
exit;
}
$email = mysqli_real_escape_string($email);