PHP Warning: Division by zero

后端 未结 8 1223
温柔的废话
温柔的废话 2020-12-20 14:46

I\'m learning php and built an experimental form-based calculator (also using html & POST method) that returns values to a table. The calculator is functional when I ent

8条回答
  •  既然无缘
    2020-12-20 15:21

    $diffPricePercent = (($actual * 100) / $itemCost) / $itemQty;
    

    $itemCost and $itemQty are returning null or zero, check them what they come with to code from user input

    also to check if it's not empty data add:

    if (!empty($_POST['num1'])) {
        $itemQty = $_POST['num1'];
    }
    

    and you can check this link for POST validation before using it in variable

    https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/

提交回复
热议问题