jeudi 28 janvier 2016

PHP nested IF statement returns parse error

I have nested IF statement to evaluate the quantity variable and process accordingly. I checked the nested IF statement on php.net and followed the same rule but still It does not work.

It parse the following error:

Parse error: syntax error, unexpected 'elseif' (T_ELSEIF) in

if(empty($quantity)){
    echo "<p>You did not enter <mark>Quantity</mark>.</p>";
    echo "<p>Please return to the form and re-enter the information <br><a href='conditionalsForm.html'>Go Back!</a>
</p>";
}
else {
    #ABS function for quantity and tax
    $quantity = abs($quantity);
    $tax = abs($tax) + 1;
    $totalCost = $quantity * $cost;

    if($quantity >= 5000){
        $totalCost = $totalCost - $discount;
    }

    #Calculate total cost to include tax.
    $totalCost = ($totalCost * $tax);
    $totalCost = round($totalCost);
    $monthlyPayment = ($totalCost / 12);

    #Nested IF to check the total cost for discount and output message
    elseif($quantity < 5000){
        echo "<p><mark>Discount will not apply as the sale is under $5,000.</p></mark>";    
    }
    endif;
}
endif;

Aucun commentaire:

Enregistrer un commentaire