Anju Anju - 9 months ago 38
PHP Question

If not variable condition is not working

I'm trying to check whether the variable value is false or true, here is my code

$print_ready_flag = $_GET['print_ready']; // i'm passing it as either true or false

echo $print_ready_flag ; // I'm getting correct value

What i'm trying to do is,

if ($print_ready_flag == false) {
file_name = "albumpdf_" . $Order['products_name'] . "_" . $OrderId . "_" . $OrderPId . ".pdf";

when doing like above expression is evaluating, But when i tried

if (!$print_ready_flag) {,

if (!(bool)$print_ready_flag)

. expression is not evaluating. Is there any way to evaluate the expression with out using comparison operator.

Answer Source

Well your all conditions are looks fine. you must need to add php `error_reporting() in your code, this will help you to find syntax and warnings.

You have a typo here:

// missing $ sign
file_name = "albumpdf_" . $Order['products_name'] . "_" . $OrderId . "_" . $OrderPId . ".pdf"; 

And its better to use print_ready=0 instead of print_ready=false for $_GET. Otherwise, you must need to check with === for value+dataType