This may be the way my server is set up, but I’m banging my head against the wall. I’m trying to say that if $action has no value or has a value that is not “add” or “delete” then have an error, else keep running the script. However, I get an error no matter what $action is.
$action = $_GET['a'];
if((!isset($action)) || ($action != "add" || $action != "delete")){
//header("location:index.php");
echo "error <br>";
}
$action is being set properly and if run something like if($action =="add") it works. This is on my local host, so it could be a settings issue.
Your logic is slightly off. The second
||should be&&:You can see why your original line fails by trying out a sample value. Let’s say
$actionis"delete". Here’s how the condition reduces down step by step:Oops! The condition just succeeded and printed “error”, but it was supposed to fail. In fact, if you think about it, no matter what the value of
$actionis, one of the two!=tests will return true. Switch the||to&&and then the second to last line becomesif (true && false), which properly reduces toif (false).There is a way to use
||and have the test work, by the way. You have to negate everything else using De Morgan’s law, i.e.:You can read that in English as “if action is not (either add or remove), then”.