Skip to content
Advertisement

whitespace error in PHP, expecting an identifier

Not sure what should be the title for this case, please edit if you have a suitable title for it. See below for the exact question.

MySQL Database:

MySQL Database

Now I want to check if the value option in “Right_Option” is having value or not. (As per above, it is not having as Right_Option is “C” & Option_C is not having any value.)

My Code:

$option = "$row['Option_".$right_option."'];";
    if($option != ''){
        //Other Codes
    }
    else{
    //other codes
    }

It gives me an error:

Error

Advertisement

Answer

You are using it wrong. Use this instead:

if(isset($row["Option_".$right_option]) && $row["Option_".$right_option] !== ''){
    //Other Codes
}
else{
//other codes
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement