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.