Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/19/2023 in all areas

  1. The syntax of an if statement looks like this: if (some condition){ //do stuff } The some condition part could be a single comparison, or multiple comparisons joined with logical operators. Note though, how there needs to be a set of parenthesis surrounding the entire condition. Now, look at your attempt: if (strpos($row["message"], 'And Click') == true) && ($viewspec_pref == "no") { You have your two conditions combined with the logical AND operator. What you're missing through, is the parenthesis that surrounds the entire combined condition. Instead, you put parenthesis around the individual conditions (which is ok, but unnecessary). Add the required parenthesis around the entire condition and you'll have something that is syntactically valid. It is a potential issue. The solution, which was never really pointed out, is that you need to strictly compare against false to determine if a match was found or not. Using a loose comparison against true will fail if your message starts with the target string (since strpos would return zero, and zero is falsely). if (strpos($row["message"], 'And Click') !== false && $viewspec_pref === "no") { It can generally be worth getting in the habit of using the strict comparison (identical) operators whenever possible, as it helps avoid such surprise outcomes. If you are using PHP 8.0 or better, you can avoid this whole problem by using str_contains instead.
    1 point
This leaderboard is set to New York/GMT-05: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.