我正在尝试转换deg -> c和c -> deg使用php。目标是使用包含公式的函数,然后拥有一个带有单选按钮和文本框的表单。用户应该能够在文本框中输入学位,单击他们选择的单选按钮(F或C),然后提交表单以接收他们的转换。我见过类似的帖子,但方法并不针对我遇到的问题。
我已经更新了我的代码,但现在得到了“死亡白页”,有人能看到我看不到的错误吗?谢谢!
HTML
<h1>Temperature Conversion</h1>
<form action='lab_exercise_6.php' method ='POST'>
<p>Enter a temp to be converted and then choose the conversion type below.</p>
<input type ='text' maxlength='3' name ='calculate'/>
<p>Farenheit
<input type="radio" name='convertTo' value="f" />
</p>
<p>Celsius
<input type="radio" name='convertTo' value="c" />
</p>
<input type='submit' value='Convert Temperature' name='convertTo'/>
PHP
<?php
//function 1
function FtoC($deg_f) {
return ($deg_f - 32) * 5 / 9;
}
//function 2
function CtoF($deg_c){
return($deg_c + 32) * 9/5;
}
if( isset($_POST['convertTo']) && $_POST['convertTo'] ==="c" ){
$farenheit = FtoC($deg_f);
print('This temperature in FARENHEIT is equal to ' . $celsius . ' degrees celsius! </br>');
}else if(isset($_POST['convertTo'])&& $_POST['convertTo']==='f'){
$celsius = CtoF($deg_c);
print('This temperature in CELSIUS is equal to ' . $farenheit . ' degrees farenheit! </br>');
}
?>
https://stackoverflow.com/questions/51654227
复制相似问题