Slip 13 - C) Implement calculator to convert distances between (both ways) miles and kilometres. One mile is about 1.609 kilometres. User interface (distance.html) has one text-input, two radio-buttons, submit and reset -buttons. Values are posted to PHP-script (distance.php) which calculates the conversions according the user input.

Solution:

slip13.html

<html>

<body>

<center>

<h2> Calculate km and mile</h2>

<form action="slip13.php" method="POST"> 

Enter Distance :<input type="text" name="distance" /><br/>

Kms:<input type="radio" name="units" value="kms" /><br/>

Miles:<input type="radio" name="units" value="miles" />

<br/>

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

<input type="reset" value="Reset" name="Reset" />

</form>

</center>

</body>

<html>

 

slip13.php 

<?php

$distance=$_POST['distance'];

$units=$_POST['units'];

if($units=='kms'){

            $miles=$distance/1.60934;

            echo'The distance is'.round($miles).'miles.';

           

}else{

            $kms=$distance*1.60934;

            echo'The distance is'.round($kms).'kms.';

}

?>

Post a Comment

0 Comments