Skip to content
Advertisement

PHP Warning: Division by zero

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 enter my values and click submit, but I keep getting two “Division by zero” errors on the last line when I first run the code. I can’t seem seem to find a logical solution or explanations when searching here or via Google. Any explanation you can provide to a newb will be appreciated.

JavaScript

Advertisement

Answer

You need to wrap your form processing code in a conditional so it doesn’t run when you first open the page. Something like so:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement