When sanitizing the $_POST passed from the controller to the model, I need to sanitize the input and there are 2 options that I can think of.
For the first one, I can nest the if
blocks like this:
if(!empty($username))
{
if(!empty($password))
{
//login the user
}
else
{
echo 'Please enter password.'
}
}
else
{
echo 'Please enter username.'
}
And the other one is like this:
if(empty($username))
{
$err[] = 'Please enter username';
}
if(empty($password))
{
$err[] = 'Please enter password.';
}
if(empty($err)){
//login the user
}
else
{
//display error
}
Which way is the preferred one and is there another, smarter way of sanitizing the input?