Jump to content
Old threads will finally start getting archived ×

Leaderboard

Popular Content

Showing content with the highest reputation on 03/13/2025 in all areas

  1. Hi CBG, Logical switches do not work like spoken words and it is easy to misunderstand them. What you really want to check is that if any one of d,c,o is yes, then error. But PHP is obeying your instructions by stopping when anyone of them is No. You need to switch the OR to an AND and it will catch the one Yes that is not allowed: <?php $p = "Yes"; //yes is different than Yes $d = "No"; $c = "No"; $o = "No"; if ($p === "Yes" && $d !== "Yes" && $c !== "Yes" && $o !== "Yes") { echo "error"; exit; } echo 'no errors'; ?> which will display an error if all three (d,c,o) are No. Otherwise, the code will display no errors. but what are you doing when a lowercase y is used? yes instead of Yes. maybe you should also use lowercase and compare with strtolower().
    1 point
  2. the 'successful' case is: $d == "Yes" || $c == "Yes" || $o == "Yes" because you are using negative logic to produce an error, the complement of this is: $d != "Yes" && $c != "Yes" && $o != "Yes" // what i think you want if ($p == "Yes" && $d != "Yes" && $c != "Yes" && $o != "Yes") { echo "error"; }
    1 point
  3. your written statement is ambiguous. please post some examples showing what result you want for different input combinations. specifically, what is the 'successful' case, which can then be complemented to produce the error case? what do you want when $p is not Yes? is that an error or does it mean that you don't care about the other three values?
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.