Friday, 28 May 2021

phps13

 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.

<html>

<body>

<form action="miles.php" method="get">

<table border="1">

<tr><td>Enter Number</td><td><input type="number" name="num" placeholder="Enter Distance"></td></tr>

<tr><td>Kilometres to Miles</td><td><input type="radio" name="ch" id="r" value=1> </td></tr>

<tr><td>Miles to Kilometres</td><td><input type="radio" name="ch" id="r" value=2></td></tr>

<tr><td><input type="submit" value="Submit"> </td>

<td><input type="reset" value="Reset"></td></tr>

</table>

</form>

</div>

</div>

</div>

</body>

</html>

 miles.php

<?php

if(isset($_GET['ch'])){

$a = $_GET['num'];

$choice = $_GET['ch'];

switch($choice){

case 1 : {

$result = $a*1.609;

echo "<center>  <b>Calculator To Convert Distances:-</b>".$result . " " ."Miles"."</center>";

break;

}

case 2 : {

$result = $a*0.621371;

echo "<center>  <b>Calculator To Convert Distances:-</b>".$result . " " ."KM"."</center>";

break;

}

}

}

?>