I'm a novice at this, and I am trying to write a simple program on PHP where a user can input the temperature in F, press Submit, and receive the answer in C. However I am getting the following warning message (only when I load the page):
Warning: Undefined array key "Fahrenheit"
I am assuming it's because the $_GET
value has not been assigned yet. However, I can't figure out how to fix it.
I also know it's not a very clean program. I tried to add RESET to the page and I got more error messages. But one thing at the time: how do I solve the above error? Here's my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Converter</title>
</head>
<body>
Enter temperature in Fahrenheit:
<form method = "get">
<input type = "number" name ="fahrenheit">
<br>
<input type = "submit" value = "Submit">
<p>
</form>
<?php
$f = $_GET["fahrenheit"];
$c = round(($f-32)*(5/9),2);
?>
</p>
<p>
<?php
echo "The temperature in Celcius is: $c";
?>
</p>
</body>
</html>