1. Home
  2. Computing & Technology
  3. PHP / MySQL

Convert Temperature

By Angela Bradley, About.com

1 of 4

Setting Up the Form

The first step in creating an online temperature conversion program, is to collect the data from the user. In our case this forms collects the degrees and the units the degrees are measured in. We are using a drop down menu for the units and giving them four options. This form uses the $_SERVER[’PHP_SELF’] command to indicate it sends the data back to itself.

Put the code below into a file called convert.php

<head>
<title>Convert Temperature</title>
</head>
<body>
<h2>Temperature Conversion</h2>
<form action = "<?php echo $_SERVER[’PHP_SELF’]; ?>"
method = "GET">
Degrees:
<input type = "text" name = "degree" size=4>
<select name="scale"> <option value="celcius">Celsius</option> <option value="fahrenheit">Fahrenheit</option> <option value="kelvin">Kelvin</option> <option value="rankine">Rankine</option> </select>
<br/>
<input type = "submit" name = "Convert Temperature"/>
</form>

Index: Convert Temperature

  1. Setting Up the Form
  2. Using IF for Conversions
  3. Adding More Conversions
  4. The Script Explained

1 of 4

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. PHP Calculator - Convert Temperature - PHP Convert Temperature

©2008 About.com, a part of The New York Times Company.

All rights reserved.