Unexpected elseif

if ($postcode > 6999 && $postcode < 8000); 
{
    echo "Tasmania";
    $postage_cost = "$22.50"; 
}   
elseif ($postcode > 5999); 
{
    echo "Western Australia";
    $postage_cost "$27.50";
}
elseif ($postcode > 4999); 
{
    echo "Southern Australia";
    $postage_cost "$15.00";
}

This is only a snippet;

( ! ) Parse error: syntax error, unexpected 'elseif' (T_ELSEIF) in C:wampwwwprojectsoutput.php on line 29

I assume the unexpected would go to all of the elseif's


There are couple of problems in your code.

First - do not use ; after IF/ElSEIF statement. It should be like

if ($postcode > 6999 && $postcode < 8000) {
    echo "Tasmania";
    $postage_cost = "$22.50"; 
} elseif ($postcode > 5999) {...

Why? Because semicolon is used to end a statement. So putting it right after your IF/ELSE/ELSEIF statement just makes it empty. Writing ; after IF would be same as writing (except that you can assign the result to variable):

$foo = ($postcode > 6999 && $postcode < 8000); //$foo would be true or false

Second - some assignment operators are missing:

$postage_cost = "$27.50"; // Note the =

Fix these and you should be good to go :)


You have put the semicolon to every if else condition remove ; Also you have not put = in some line so add that. You can try the following code

if ($postcode > 6999 && $postcode < 8000) {
    echo "Tasmania";
    $postage_cost = "$22.50"; 
    }   
    elseif ($postcode > 5999) {
    echo "Western Australia";
    $postage_cost = "$27.50";
    }
    elseif ($postcode > 4999) {
    echo "Southern Australia";
    $postage_cost = "$15.00";
    }

Remove the semicolon from if and elseif statement

so code look like this

if ($postcode > 6999 && $postcode < 8000) {
echo "Tasmania";
$postage_cost = "$22.50"; 
}   
elseif ($postcode > 5999) {
echo "Western Australia";
$postage_cost = "$27.50";
}
elseif ($postcode > 4999) {
echo "Southern Australia";
$postage_cost = "$15.00";
}
链接地址: http://www.djcxy.com/p/69854.html

上一篇: 两个水平divs在一个div中的流体高度

下一篇: 意外的elseif