Pergunta

if($action == "send"){
$_POST['name'] =        $name ;
$_POST['email'] =       $email ;
$_POST['phone'] =       $phone  ;


  if(!empty($name) || !empty($email) || !empty($phone)){

  .....
 } else {

  $msg = 'All fields required';

}

//whatever I do only shows $msg.

//already tried that too

  if(!empty($_POST['name']) || !empty($_POST['email']) || !empty($_POST['phone'])){
  ....
   }

What Im trying to do is a form that email me the data, and I want all fields to be filled so maybe Im writing the if statement the wrong way. sorry if I didnt explained well before.

Foi útil?

Solução

Your code reads:

If name is not empty, or email is not empty, or phone is not empty

This means that as long as at least one of them are non-empty, then you're good!

Pretty sure that's not what you meant. You want:

If name is not empty, AND email is not empty, AND phone is not empty

Use && instead of || and it should just work!

Outras dicas

I think you're getting confused by all the negatives involved here. I suspect what you're after is:

if (!(empty($name) || empty($email) || empty($phone))) {
    ...
} else {
    $msg = 'All fields required';
}

Which would be better written (in my opinion) as:

if (empty($name) || empty($email) || empty($phone)) {
    $msg = 'All fields required';
} else {
    ...
}
if($name=='' || $email=='' || $phone=='')
{
    $msg='All fields required';
}
else 
{
    ..............
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top