Slip 18 - A) Write a PHP program to create a simple distance calculator that can accept distance in meters from user. Convert it into centimeter or kilometer according to user preference. (use radio buttons and Self Processing form)

 Solution:

<html>
<?php
$n=$_GET["n"];
$n1=$_GET["n1"];
$a=$_GET["a"];

?>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="GET">
ENTER distance IN  meter:<input type="number" name="n"><br>
ENTER distance IN  kilometer:<input type="number" name="n1"><br>
<input type="radio" name="a" value="1">Convert to meters
<input type="radio" name="a" value="2">Convert to kilometers<br>
<input type="submit" value="Ok">
<br>
<?PHP
switch($a)
{

case 1:$c=round($n1*1000);
  echo"Distance in  meters is $c";
       break;
case 2:$c=round($n/1000);
    echo"Distance IN Kilometers is $c"; 
    break;
}      
?>
</form>
</html>

Post a Comment

0 Comments