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)||EasyCoding45
In this Tutorial we are going to learn how we can Write a PHP program to create a simple distance calculator that can accept distance in meters from user. and then Convert it into centimeter or kilometer according to user preference(by using radio buttons and Self Processing form)
Program ::--
<html>
<head>
<title>Distance Conversion</title>
<body>
<?php
if($_SERVER['REQUEST_METHOD']=='GET')
{
?>
<form action="<?php echo$_SERVER['PHP_SELF']?>" method="POST">
Enter Distance in meter :<input type=text name=t1><br>
<input type=radio name=r1 value=1>Convert into Centimeter<br>
<input type=radio name=r1 value=2>Convert into Kilometer<br>
<input type=submit value=Convert><br>
</form>
<?php
}
else if($_SERVER['REQUEST_METHOD']=='POST')
{
$dist=$_POST['t1'];
$op=$_POST['r1'];
switch($op)
{
case 1:
echo "Conversion from meter to centimeter is :";
$cm=$dist*100;
echo "$cm cm";
break;
case 2:
echo "Conversion from meter to Kilometer is :";
$km=$dist/1000;
echo "$km km";
break;
}
}
?>
</body>
</html>
I am glad that you liked it. Thank you so much.
ReplyDelete