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;

  1. PHP program to convert Fahrenheit to Celsius 
  2. PHP program to convert Fahrenheit to Celsius with form
  3. 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.

<!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.

<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 : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="far">
<br><br>
<input type="submit" name= "submit" value="Convert">
<input type="reset" value="Reset">
   </center>

<?php
if(isset($_POST['submit']))
{
	$f= $_POST['far'];
	$c= ($f - 32) * (5/9);
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span><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.

<!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 : &nbsp;&nbsp;&nbsp;&nbsp;<input type="num"  name="far">
<br><br>
<input type="submit" name="conv" value="Convert">
<input type="reset"  value="Reset">
  <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 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span><center><label class='col-sm-2 control-label' >Temprature in Celcius =</label> <input class='easypositive' value=$c ></span></center>";
	
	
	?>
</body>
</div>
</html>

Database

php program to convert fahrenheit to celsius convert

figure: php program to convert Fahrenheit to Celsius.

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.

Leave a Reply

Your email address will not be published. Required fields are marked *