Member Avatar for jpknoob

Hello, i am trying to write a bit of script that will add a delivery cost based on the country code which is provided from a form. Everything works, except my last else statement. As an example, i am trying to make the delivery 1.15 if the country code is GB, 2.15 for EU countries that have been listed and 3.15 for any other code that has not been mentioned. When i select the UK from the dropdown list, the delivery appears as it should and when i go back and change it to a EU country the delivery updates correctly. However, when i select a non-EU country, the output remains at 2.15, can anyone lend a hand?

if ($strDeliveryCountry == GB){
$delivery=1.15;
}
else {
 if ($strdeliveryCountry == AI||AD||AM||AT||BY||BE|| etc etc){
 $delivery=2.15;
 } else $delivery=3.15;
}

Why not try something like:

if($country == 'GB')
    $delivery = 1.15;
elseif(in_array($county, array('AI', 'AD', 'AM', 'AT', 'BY', 'BE'))
    $delivery = 2.15;
else
    $delivery = 3.15;

All, variable names are case sensitive, and strings should be wrapped in single quotes (or double depending on usage). This may help explain the odd behaviour you've encountered.

R.

Member Avatar for jpknoob

Tried your code and it worked perfectly, you just forgot to add another closed quote after the else if ;)

Many Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.