If statement not workin

Hi,
i have a long if statement, which doesn’t seem to work when i add something more than $q1, i.e its taking one condition, what am i doing wrong?


if(($qs ==='party') || ($q2 === 'clothes') || ($q3 === 'shopping') || ($q5 === 'Sunbathing') || ($q6 === 'mini')){
   // do something
}

I assume you have echoed out the variables being passed to the if statement to see what they contain; also should $qs in your post be $q1?

didn’t understand the first part of the question, and yes $qs is a post variable coming from a form page

$q1, i.e its taking one condition

Because you’re using OR so if ANY of these values match and are of the same type (===), your IF statement reads true. If you need them all to match use && instead of ||

&& stands for AND, whereas what i have in the form are 6 questions and each questions have 4 options, it check to see if any one question is choosen that is given in the if statement then it will run. r u sure && is right? as we i am dealing with radio button, should it be OR?

Edit : or can i have multiple radio buttons on each question selected?

Then you do want OR.

it helped, i have many questions in my form and each form can be selected. and i was missing () outside my if condition.
Thank you for the help

Did you get it figured out? (had to step away for a bit)

Not sure how you are defining those variables but If the IF statement is failing because maybe a radio button was not selected, you might add something like this so those variables are always defined.


$qs = (isset($_POST['qs']) ? "{$_POST['qs']}" : '');
$q1 = (isset($_POST['q1']) ? "{$_POST['q1']}" : '');
$q2 = (isset($_POST['q2']) ? "{$_POST['q2']}" : '');

etc.