ballhogjoni Posted April 3, 2007 Share Posted April 3, 2007 How do I get rid of this warning message? Warning: Division by zero in /home/realfina/public_html/tests/school/FindtheBugs.php on line 48 <?php $milesTraveled=$_POST['milesTraveled']; $gallonsOfGasUsed=$_POST['gallonsOfGasUsed']; $milesPerGallon = $milesTraveled / $gallonsOfGasUsed; ?> <form action="" method=POST> <table width="300" align="center"> <tr><td align="center"><h2><b>Question 2</b></h2></td></tr></table> <table width="300" align="center"> <tr> <td align="right"> Miles Traveled</td><td><input type="text" name="milesTraveled" value="" /> </td> </tr> <tr> <td align="right"> Gallons Of Gas Used</td><td><input type="text" name="gallonsOfGasUsed" value="" /> </td> </tr> </table> <table width="300" align="center"> <tr> <td width="10"> </td><td align="center"><input type="submit" value="Find the Miles Per Gallon" /> </td></tr></table> <table align="center" width="300"> <tr> <td align="center"> The average of the Miles Traveled & the Gallons Of Gas Used you just submitted is: <span style="background-color:#FFFF00"><font color="#FF0000"><b> <?php if ($milesPerGallon=="0") echo "First you must input some numbers in the form above and then click the \"Find the Miles Per Gallon\" button"; else echo $milesPerGallon;?></b></font></span> </td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/45357-solved-warning-division-by-zero-in-homerealfinapublic_htmltestsschoolfindthebugs/ Share on other sites More sharing options...
fert Posted April 3, 2007 Share Posted April 3, 2007 <?php if(isset($_POST['gallonsOfGasUsed'])) { $milesTraveled=$_POST['milesTraveled']; $gallonsOfGasUsed=$_POST['gallonsOfGasUsed']; $milesPerGallon = $milesTraveled / $gallonsOfGasUsed; } ?> Link to comment https://forums.phpfreaks.com/topic/45357-solved-warning-division-by-zero-in-homerealfinapublic_htmltestsschoolfindthebugs/#findComment-220250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.