PHP: Avoid undefined index?

前端 未结 9 1888
闹比i
闹比i 2021-01-17 11:18

Every time a POST value is not equal to the list of values set in an array will return: Undefined Index error, I made an if statement but is not working.

Here\'s the

9条回答
  •  借酒劲吻你
    2021-01-17 11:51

    you can check whether the index 'product' is defined in the same if statement ..

    if (isset($_POST['product']) && $products[$_POST['product']] == $_POST['product']) {
        do everything;
    }
    else {
        echo "This item is not available";
    }
    

提交回复
热议问题