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
If it shows an error on the first run only, it's probably because you haven't sent any POST data. You should check for POST variables before working with them. Undefined, null, empty array, empty string, etc. are all considered false; and when PHP auto-casts that false boolean value to an integer or a float, it becomes zero. That's what happens with your variables, they are not set on the first run, and thus are treated as zeroes.
10 / $unsetVariable
becomes
10 / 0
Bottom line: check if your inputs exist and if they are valid before doing anything with them, also enable error reporting when you're doing local work as it will save you a lot of time. You can enable all errors to be reported like this: error_reporting(E_ALL);
To fix your specific problem: don't do any calculations if there's no input from your form; just show the form instead.
Try using
$var = @($val1 / $val2);