문제

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');

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top