if condition in php is not running

1

I have the following code in a PHP file:

<?php if($debug == 1){ ?>
    <button id="btn-debug" class="btn btn-default"><i class="fa fa-bug"></i></button>
<?php } ?>

The variable debug is called here in another file:

$debug = data_setting_value($dbc, 'debug-status');

The data_setting_value function is contained in another file, this function will fetch a table in the database from the value of the field value , which in this case is 1

function data_setting_value($dbc, $id){

    $q = "SELECT * FROM settings WHERE id = '$id'";
    $r = mysqli_query($dbc, $q);
    $data = mysqli_fetch_assoc($r);

    return $data['value'];
}

The problem is that the button is not appearing on the page, and you should have seen that the value field in the database is 1

    
asked by anonymous 18.02.2017 / 21:12

1 answer

0

It is recommended to use === (three comparison signs) instead of == (two comparison signs).

See the explanation here: link

I do not think the problem is in PHP, but rather in your data.

Make the following changes:

In the file that contains: $debug = data_setting_value($dbc, 'debug-status');

<?php
// ..
// ..
$debug = data_setting_value($dbc, 'debug-status');
print_r($debug);
// ..
// ..
?>

And see what's coming back.

In the function file: data_setting_value

function data_setting_value($dbc, $id){

    $q = "SELECT * FROM settings WHERE id = '$id'";
    $r = mysqli_query($dbc, $q);
    $data = mysqli_fetch_assoc($r);

    print_r($data); // <-- Insira este print_r

    return $data['value'];
}

And see the result of SELECT .

    
19.02.2017 / 15:26