foreach ($_POST as $nazwa_checkboxa=>$id) {
    $s = "SELECT uprawnienie FROM user WHERE Id_user=".$id;
    $helpdesk = 0;

    if ($s == 0) {
        $helpdesk = 1;
    }

    $z = "UPDATE user SET uprawnienie = ".$helpdesk." WHERE Id_user=".$id;
    $wynik = $polaczenie->query($z);
    $zmienione++;
}

uprawnienie返回0 = normal用户和1 = administrator
更新总是将值设置为1,我可以将用户更改为管理员(0到1),但1到0不起作用

最佳答案

实际上,您可以使用一个查询来完成,例如:

update user
set uprawnienie = (SELECT if(uprawnienie=1,0,1) FROM user WHERE Id_user = '<id>')
where Id_user = '<id>'

07-24 09:44