Question

I need some help

I want my script to run if the mysqli_query returns off I set value of id=1 to off

But my script does not run. But if i replace if off with false it works fine.

What can be wrong ?

 $query3=mysqli_query($con,"SELECT * FROM choice WHERE id=1");
 $query4=mysqli_fetch_array($query3);
 if ($query4['choice'] == off) {
    $output = shell_exec('sudo python test1.py');

No correct solution

OTHER TIPS

Assuming this isn't a MySQL problem, try this:

 if (strcmp($query4['choice'], 'off') == 0) {
    $output = shell_exec('sudo python test1.py');
 }

Or even:

 if ($query4['choice'] === 'off') {
    $output = shell_exec('sudo python test1.py');
 }

In the first example, we are comparing the string for equality, if zero is returned, there is no difference, meaning the strings are identical in every way.

In the second example, we are checking for type with the triple equal sign ===, so it will compare string to string properly as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top