I am trying to embed a self-referencing PHP script inside an HTML form with following code:
Undefined index: conv
<form action = "<?php $_SERVER['PHP_SELF'] ?>" method = "post">
<input type = "number" id = "temp2" name = "temperature2" placeholder = "28">
<label for = "temp2"> degrees </label>
<select>
<option name = "conv" value = "f"> Fahrenheit </option>
<option name = "conv" value = "c"> Celsius </option>
</select>
<input type = "submit" value = "equals">
<?php
$type = $_POST["conv"];
$tmp = $_POST["temperature2"];
if ($type == "f") {
$newTmp = (9/5 * $tmp) + 32;
echo $newTmp . " degrees Celsius.";
}
elseif ($type == "c") {
$newTmp = (5 * ($tmp - 32)) / 9;
echo $newTmp . " degrees Fahrenheit.";
}
?>
</form>
And I am getting this messages: Notice: Undefined index: conv Notice: Undefined index: temperature2
Everything worked fine when the php script was in another file. Anyone knows what am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire