PHP program to convert Fahrenheit to Celsius
In this tutorial, we will try to learn the followings;- PHP program to convert Fahrenheit to Celsius
- PHP program to convert Fahrenheit to Celsius with form
- PHP program to convert Fahrenheit to Celsius with database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php $far = 89; $cel=($far - 32) * (5/9); echo "Temprature in Fahrenheit is : $far". "<br />"; echo "Temprature in Celcius is : $cel" ; ?> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<html> <head> <meta charset="utf-8"> <strong><h1>Convert fahrenheit to Celcius</h1></strong> </head> <body align="center"> <center> <form method="post"> <br><br><br> Enter Temprature in Fahrenheit : <input type="text" name="far"> <br><br> <input type="submit" name= "submit" value="Convert" style="font-size: 2em; background-color: #f27669;"> <input type="reset" value="Reset" style="font-size: 2em; background-color: #4c4c4c;"> </center> <?php if(isset($_POST['submit'])) { $f= $_POST['far']; $c= ($f - 32) * (5/9); echo " <span style='background-color: #e4ddcb'><center><label class='col-sm-2 control-label' >Temprature in Celcius =</label> <input class='easypositive' value=$c ></span></center>"; } ?> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <div align="center"> <body> <center> <form method="post"> <br><br><br> Enter Temprature in Fahrenheit : <input type="num" name="far"> <br><br> <input type="submit" name="conv" value="Convert" style="font-size: 2em; background-color: #f27669;"> <input type="reset" value="Reset" style="font-size: 2em; background-color: #4c4c4c;"> <br><br><br><br><br><br> </center> <?php $server = "localhost"; $user="root"; $password=""; $database="celcius"; $con=mysqli_connect("localhost","root","","celcius"); if($con){ echo" all good"; } $f= $_POST['far']; $c= ($f - 32) * (5/9); if(isset($_POST['conv'])) { $res= mysqli_query($con,"INSERT INTO ftoc (fahrenheit,celcius) VALUES ('$f','$c')"); } echo " <span style='background-color: #e4ddcb'><center><label class='col-sm-2 control-label' >Temprature in Celcius =</label> <input class='easypositive' value=$c ></span></center>"; ?> </body> </div> </html> |
