解析错误:语法错误,意外的'&&'(T

我正在为学校做一个php脚本,并且我在这些行中遇到了一个错误。

// calculate total
$total_price = $crystal_price * $item_numbers + $postage_price;
if ($coupon_code=="FREEPOST" && $total_price >= 1000 ) $postage_price = 0 ; && $total_cost = $item_numbers * $crystal_price
else if ($coupon_code=="HALFPOST" && $total_price >= 400 ) $postage_price = $postage_price * 0.5 ; && $total_cost = $item_numbers * $crystal_price + $postage_cost * 0.5 ;

如果我删除if语句的第二部分,它工作正常,但是我需要它,有什么方法可以解决这个问题吗?


它在第二行&& $total_cost = $item_numbers * $crystal_price 。 那些&&在那里&&

它有助于您将代码调整一点:

// calculate total
$total_price = $crystal_price * $item_numbers + $postage_price;
if ($coupon_code=="FREEPOST" && $total_price >= 1000 ) 
  $postage_price = 0 ; 
  && $total_cost = $item_numbers * $crystal_price
else if ($coupon_code=="HALFPOST" && $total_price >= 400 ) 
  $postage_price = $postage_price * 0.5 ; 
  && $total_cost = $item_numbers * $crystal_price + $postage_cost * 0.5 ;

如果你这样做,你可以更容易地发现错误。 看上面的代码,我想你也忘了一些大括号:

// calculate total
$total_price = $crystal_price * $item_numbers + $postage_price;
if ($coupon_code == "FREEPOST" && $total_price >= 1000) 
{
  $postage_price = 0; 
  $total_cost = $item_numbers * $crystal_price;
}
else if ($coupon_code == "HALFPOST" && $total_price >= 400) 
{
  $postage_price = $postage_price * 0.5; 
  $total_cost = $item_numbers * $crystal_price + $postage_cost * 0.5;
}
链接地址: http://www.djcxy.com/p/69465.html

上一篇: Parse error: syntax error, unexpected '&&' (T

下一篇: Parse error: syntax error, unexpected T