Parse error: syntax error, unexpected '&&' (T

I'm doing a php script for school and I've got an error with these lines.

// 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 I remove the 2nd part of the if statement it works fine, however I need it, is there any way I can fix this?


It's on the second line && $total_cost = $item_numbers * $crystal_price . Those && are out of place there.

It helps if you align your code a little:

// 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 you do, you can spot errors more easily. Looking at the code above, I think you also forgot some braces:

// 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/69466.html

上一篇: 语法错误,意外的T

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