Search code examples
phppostisset

if isset or empty equals var


Is it possible to combine $_POST with isset in one row to avoid the error Notice: Undefined index:?

Example (doesn't work):

if(isset($_POST["VALUE"]) == "ON") echo "ON";

Solution

  • No, you can't since isset() returns true or false. But you can do the following:

    if(isset($_POST['VALUE']) AND $_POST['VALUE'] == "ON") {
        echo "ON";
    }