-2

I am getting this error in php which i quite don't understand why it is happening. Can anyone shed some light on why this is an error ? I am a beginner in php so please bear with me. Any sort of feedback would be greatly appreciated.

<!DOCTYPE html>
 <head> 

 <title> Distance </title>
   </head>

   <body>

   <?php


 function distance($lat,$lng,$d){

   $distannce = ($lat - $lng) / $d;

   return $distannce;

   }

$stand = distance(isset($_POST['val']),isset($_POST['value']),isset($_POST['dist']));

  ?>
    <form method = "post">



   <input type="checkbox" name="dtLatLng_Lat"  checked="checked"  />
    <label for="dtLatLng_Lat"> Latitude </label>&nbsp &nbsp &nbsp;

  base
  <input type="text"name="val"  size ="6"   style="width:60px"; /> 

    dist
    <input type="text"name="dis" id="dis" size = "1"; /> 
    <label for="dis">  </label>
    <br>

  <input type="checkbox" name="dtLatLng" id="dtLatLng" checked="checked" />
   <label for="dtLatLng"> Longitude </label>&nbsp &nbsp;
   base
   <input type="text" name="value" id="dtvalue" size ="6" style="width:60px";/> 
    <label for="dtvalue"> </label>&nbsp;

dist
   <input type="text"name="dist" id="dtval" size ="1"; /> 

   <br>

     <input type="submit" name="submit" value="Submit" />

    </form>
   </body>
     </html>

1 Answers1

0

In your code $d becomes zero due to this it shows "Warning: Division by zero Error in php duplicate"

Try this

function distance($lat,$lng,$d){

   if($d != 0)
   {
       $distannce = ($lat - $lng) / $d;
   }
   else
   {
       $distannce = 0;
   }

   return $distannce;

}
Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40