Php form: if statement question

i have a form and the form allows the visitor to select a color, there are 4 colors to choose from. when that color is selected i want the results page to then display a certain sku for each accessory.

i have it writing the sku on the next page, and everything works except when the color is selected the only number on the following page that displays correct is the 1st one ($skusill) all the other sku’s are ignored and default to the brown sku values. should this be a if else? am i not supposed to separate the lines with “;”…i’m lost.

please help. thanks in advance. as you can tell I am a novice (is there a level below novice?!)
[php]

{ if ($color == Cream)
$skusill=1445532;
$sku36lintel=1445554);
$sku48lintel=1445555;
$skulight=1445536;
$skuutility=1445540;
$skuhearth=1445528;
$skutrim=1445544;
$skukey=1445548;
$skuquoin=1445552;
}

{ if ($color == Grey)
$skusill=1445560;
$sku36lintel=1445582;
$sku48lintel=1445583;
$skulight=1445564;
$skuutility=1445568;
$skuhearth=1445556;
$skutrim=1445572;
$skukey=1445576;
$skuquoin=1445580;
}

{ if ($color == Natural)
$skusill=1445504;
$sku36lintel=1445526;
$sku48lintel=1445527;
$skulight=1445508;
$skuutility=1445512;
$skuhearth=1445500;
$skutrim=1445516;
$skukey=1445520;
$skuquoin=1445524;
}
{ if ($color == Brown)
$skusill=1445588;
$sku36lintel=1445610;
$sku48lintel=1445611;
$skulight=1445592;
$skuutility=1445596;
$skuhearth=1445584;
$skutrim=1445600;
$skukey=1445604;
$skuquoin=1445608;
}

[/php]

[php]if ($color == ‘Cream’){
$skusill=1445532;
$sku36lintel=1445554);
$sku48lintel=1445555;
$skulight=1445536;
$skuutility=1445540;
$skuhearth=1445528;
$skutrim=1445544;
$skukey=1445548;
$skuquoin=1445552;
}[/php]

Use the if statements in this format.

Hello mike, i have checked your code and found that your doing wrong. Please use below code. It will works fine for you. [php] <? if($color == 'Cream') { $skusill=1445532; $sku36lintel=1445554); $sku48lintel=1445555; $skulight=1445536; $skuutility=1445540; $skuhearth=1445528; $skutrim=1445544; $skukey=1445548; $skuquoin=1445552; } elseif($color == 'Grey') { $skusill=1445560; $sku36lintel=1445582; $sku48lintel=1445583; $skulight=1445564; $skuutility=1445568; $skuhearth=1445556; $skutrim=1445572; $skukey=1445576; $skuquoin=1445580; } elseif($color == 'Natural') { $skusill=1445504; $sku36lintel=1445526; $sku48lintel=1445527; $skulight=1445508; $skuutility=1445512; $skuhearth=1445500; $skutrim=1445516; $skukey=1445520; $skuquoin=1445524; } elseif($color == 'Brown') { $skusill=1445588; $sku36lintel=1445610; $sku48lintel=1445611; $skulight=1445592; $skuutility=1445596; $skuhearth=1445584; $skutrim=1445600; $skukey=1445604; $skuquoin=1445608; }

?>
[/php]
I hope this will helpful for you…
Reply your feedback.
SR

Why would elseif be needed in this instance?
If your checking for pre-set values?

Either Cream, Grey, Natural or Brown must be selected. There are no variants so I would have thought elseif would be pointless.

Please correct me if I’m wrong

Lothop,

You are correct, you do not need the elseif’s.

They ARE used to make the code more readable. “Readable” means, when OTHERS read your code, not you.
LOL… Coding is in the mind of the owner, with a little help from others… Many ways to do it!

One note, the code you first posted had all the routines inside of brackets! {} No sense to that!

One note, the code you first posted had all the routines inside of brackets! {} No sense to that!
I dont get what you mean. Do you mean original poster?

By the way, I just noticed under cream, $sku36lintel=1445554);
Should be $sku36lintel=1445554;

Sorry, Lothop, I meant Mike… On his first post, he had brackets around various if’s and assignments, unless he was showing us only part of the problem code… Either way, the else’s are not needed…

Sponsor our Newsletter | Privacy Policy | Terms of Service