我一直在努力工作一個簡單的基於窗體的溫度轉換器,但我目前正在獲得一個白色的屏幕,我看不出有什麼問題的代碼。此外,任何有關最佳實踐的想法/建議都非常受歡迎!運行PHP溫度轉換器的問題
<?php // convert.php
if (isset($_POST['temperature']))
$temp = sanitize_string($_POST['temperature']);
if (isset($_POST['scale']))
{
if ($_POST['scale'] == 'fah')
$conv = 'fah';
$output = intval((5/9) * ($temp - 32));
elseif ($_POST['scale'] == 'cel')
$conv = 'cel';
$output = intval((9/5) * ($temp + 32));
else
$output = '';
}
?>
<html>
<head>
<title>Temperature converter</title>
</head>
<body>
<?php
if (isset($_POST['submitted']) and isset($conv))
{
if ($conv == 'fah')
print("$temp degrees Fahrenheit is $output degrees Celcius");
elseif ($conv == 'cel')
print("$temp degrees Celcius is $output degrees Fahrenheit");
}
?>
<form method="post" action="convert.php">
<label>Temperature <input type="text" name="temperature"></label>
<label>Celcius <input type="radio" name="scale" value="cel"></label>
<label>Fahrenheit <input type="radio" name="scale" value="fah"></label>
<input type="hidden" name="submitted" value="yes">
<input type="submit">
</form>
</body>
</html>
<?php
print_r($_POST);
function sanitize_string($var)
{
$var = stripslashes($var);
$var = htmlentities($var);
$var = strip_tags($var);
return $var;
}
?>
打開php.ini中的錯誤報告。 – 2011-04-12 14:43:41