LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   problem with php logic (https://www.linuxquestions.org/questions/programming-9/problem-with-php-logic-515058/)

veritas 12-30-2006 11:27 PM

problem with php logic
 
Hi,

If I leave out the ?name= from logic.php it correctly displays "no name specified." But if I do logic.php?name=Jack it displays wrong name. Same with a bogus value. I tried changing the operator to !=, but the code outputs "name accepted" for any value using this method. :confused: I would appreciate any tips with this.
Code:

<?php
        $var = $_GET["name"];

        if (!$var)
        {
                echo "no name specified";
        }
        else
        {
                if ($var !== ("Jack" || "Jill" || "Ted" || "Sarah"))
                {
                        echo "wrong name";
                }
                else
                {
                        echo "name accepted";
                }
        }
?>


pnellesen 12-30-2006 11:51 PM

I think your evaluation needs to be as follows:
Code:

if ($var != "Jack" && $var != "Jill" && $var != "Ted" && $var != "Sarah")
If any of those names is entered, you should see "name accepted"

veritas 12-31-2006 12:01 AM

Thanks! That did the trick


All times are GMT -5. The time now is 08:20 AM.