-2

I have built this if statement in PHP, but the else part of it is not showing any effects -

if($fcode=='Ok' || 'F') {
    $name = $_POST['udf1'];
    $email = $_POST['udf2'];
    $mobile = $_POST['udf3'];
    $city = $_POST['udf4'];
} else {
    $name = 'NA';
    $email = 'NA';
    $mobile = 'NA';
    $city = 'NA';
}

What I aim to do is, if the fcode variable's value is either of 'Ok' or 'F', get the POST parameters and store them into some variables ($name, $email, etc.). If it's not 'Ok' or 'F', store 'NA' into those variables.

What's happening is, the main if's code is working (when the fcode = Ok || F) as expected, but the else's code does not do anything.

Did I do anything wrong? What should I do now?

Any help is appreciated Thanks!

kartik
  • 550
  • 1
  • 6
  • 19
  • 1
    I put an answer for you, your first line looks like the problem: After your "||" logical operator, you are only putting a string in. I assume you want to run everything in the "IF" section if $fcode returns "Ok" or "F". Try: if($fcode=='Ok' || $fcode=='F') – OneAdamTwelve Sep 23 '20 at 16:56
  • Thanks @OneAdamTwelve, that worked for me – kartik Sep 23 '20 at 17:19

1 Answers1

1

I think it's because of your OR statement. Try replacing the below line:

if($fcode=='Ok' || $fcode=='F') {

OneAdamTwelve
  • 236
  • 1
  • 3
  • 14
  • That's brilliant! That worked for me like a charm. I just forgot to add the variables name again - Thanks a lot! – kartik Sep 23 '20 at 17:18