Validation problem

I want to validate a form with php,so I wrote bellow code but as I saw in debug even I set nothing at these fields the if statement does not work!
What is wrong?


$insurance_id = trim(strip_tags($_POST[‘insurance_id’]));
…etc
if ($insurance_id==“” || $person_id== “” || $licence_id==“” || $first_local_licence_date==“”)
{
header(‘location:incurance_new.php’);
} else {

    //do something;
}

You could try bracketing the individual conditions, see if that works.

if (($insurance_id=="") || ($person_id== "")  || ($licence_id=="") ||   ($first_local_licence_date==""))

It won’t be of any effect.

How do you know “it does not work”?

If your variables are all empty, then if condition does work.

So, thinking logically, we can conclude that either your variables aren’t empty or your condition does work.

You are supposed to verify both statements.
Unfortunately, nobody can tell whether your variables are empty or not. You have to do it yourself.
Same for the “not working” condition. Did you try to echo anything within it to make sure it doesn’t?

First stop, check for typos, especially a missing = sign. Always difficult when the code posted is not the actual code you have. Also after the header() line you should call exit() to stop execution of the remainder of the script.

I presume they are not forwarded to the location in the header.
But the OP could try something more obvious for testing like:-

{ echo "There are blank fields in the form.";}
else { echo "The form is complete.";}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.