PHP program to convert Fahrenheit to celsius convert
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
PHP program to convert Fahrenheit to Celsius.
In this example, programmer stores the values in the variables. However, if you interested to see the program about taking values in the form, please see example 2.
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> |
PHP program to convert Fahrenheit to Celsius with form
In this example, we will take the inputs from the user and store them in variables.
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> |
PHP program to convert Fahrenheit to Celsius with the database.
In this example, we will take the inputs from the user and temporarily store them in variables and then finally stores them permanently in the database.
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> |
Database