由于v.4到v5迁移,PHP脚本不再起作用

问题描述:

最近我的webserver从PHP v.4迁移到v.5.3。我知道,我知道,很长一段时间:)由于v.4到v5迁移,PHP脚本不再起作用

但是现在当用户输入所需的数据时,我的一些脚本不显示结果。这里是脚本:

<?php 
if ($ok) { 

    if ($heightft == "" || $heightin == "" || $weight == "") { 
     $error = "<br><FONT COLOR=#FF0000>One of the fields above was not completed.</FONT><br>"; 
    } else { 
     $bmi = $weight * 703/(($heightft * 12 + $heightin) * ($heightft * 12 + $heightin)); 
     $bmiString = number_format($bmi,2,".",""); 
     echo "<table border='1' cellpadding='10' bordercolor='0000FF'><tr><td><strong>Your BMI is: " . $bmiString; 
echo "<br><br></strong>"; 

     if ($bmi <= 18.50) { 
      echo "You are classified as <strong>Underweight</strong>."; 
     } elseif ($bmi <= 24.99) { 
      echo "You are classified as <strong>Normal</strong>."; 
     } elseif ($bmi <= 29.99) { 
      echo "You are classified as <strong>Overweight</strong>."; 
     } else { 
      echo "You are classified as <strong>Obese</strong>.</td></tr></table></bordercolor>"; 
     }  
    } 
} 

?> 

<?php echo $error;?> 
+3

'$ ok'在哪里设置? – hek2mgl 2013-04-21 20:27:00

+5

不要紧,升级PHP晚了,你*仍然*使用''? – 2013-04-21 20:32:16

看起来像你期待register_globals上。这现在是默认关闭的。

您应该使用$_GET['heightft']$_POST['heightft']取决于窗体方法来访问此数据。

+0

应该从'$ _GET ['var']'或'$ _POST ['var']'而不是'$ var'读取的变量是:'ok','heightft','heightin'和'weight' 。 – drealecs 2013-04-21 20:36:42

+0

感谢您的回复。所以为了澄清,我会改变:if($ heightft ==“”|| $ heightin ==“”|| $ weight ==“”)if($ _GET ['heightft'] ==“”|| $ _GET ['heightin'] ==“”|| $ _GET ['weight'] ==“”)?再次感谢 – user1745590 2013-04-21 20:58:57

+0

您可能需要编辑if($ ok){'to'if($ _GET ['ok']){'too。 – drealecs 2013-04-22 01:21:40