I have been working on the following simple temperature conversion using HTML and PHP. It is my first attempt at using PHP and I can't seem to get it right.
I am sure there are lots of errors in my code so please be patient!
Here is what I have:
<!DOCTYPE HTML>
<html>
<head>
<title>Temp Conversion</title>
<meta charset="utf-8">
<body>
<form name="tempConvert" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<table>
<tr>
<td>Enter value to convert</td>
<td><input type="text" name="valueConvert" id="valueConvert" size="15"></td>
</tr>
<tr>
<td>Convert to:</td>
<td><select name="convertType" id="convertType" size="1">
<option disabled> Select a measurement type</option>
<option value="celsius">Celsius</option>
<option value="fahrenheit">Fahrenheit</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" name="btnConvert" id="btnConvert" value="Convert"></td>
<td><input type="reset" name="btnReset" id="btnReset" value="Reset"></td>
</tr>
</form>
<?php
$valueConvert = $_POST['valueConvert'];
$convertType = $_POST['convertType'];
function tempConvert($valueConvert, $convertType){
if($convertType == "fahrenheit"){
$conversion = ((9/5)*$valueConvert) +(32);
}
else if ($convertType == "celsius"){
$conversion = ($valueConvert - 32) * (9/5);
}
return $conversion;
echo "The initial temperature was $valueConvert. The new temperature is $conversion.";
}
?>
</body>
</html>
I can't figure out how to pass the users textbox input and dropdown list selection to the php function.