Undefined index error PHP

前端 未结 9 867
春和景丽
春和景丽 2020-12-01 08:24

I\'m new in PHP and I\'m getting this error:

Notice: Undefined index: productid in /var/www/test/modifyform.php on line 32

Notice: Undef

9条回答
  •  眼角桃花
    2020-12-01 08:45

    This is happening because your PHP code is getting executed before the form gets posted.

    To avoid this wrap your PHP code in following if statement and it will handle the rest no need to set if statements for each variables

           if(isset($_POST) && array_key_exists('name_of_your_submit_input',$_POST))
            {
                 //process PHP Code
            }
            else
            {
                 //do nothing
             }
    

提交回复
热议问题