Laravel-将null设置为模型列无效

时间:2019-05-28 00:01:10

标签: php laravel

我试图在“模型”列上设置一个空值,但该值将被忽略并且不会更新。

if($rol_colegio)
    $update_pl['rol_colegio'] = $rol_colegio; //$rol_colegio may be null

$usuario->update($update_pl);

当我尝试使用非空数据时,数据不会成功更新,但是如果变量为null,则该条目不会被更新。

这是什么原因?

2 个答案:

答案 0 :(得分:3)

$rol_colegion = null与条件if($rol_colegio)不匹配。

只需删除if($rol_colegio)

答案 1 :(得分:0)

只需这样做。

if (isset($_POST['email_confirm'])) { 
    // receive all input values from the form
    $code = $_SESSION['gen_code']; // in case you would wish to store and retrieve code from db, replace this code with one which retrieved from db by email id... SELECT code from user where email=$email
    $user_code = mysqli_real_escape_string($db, $_POST['code']);
    // check whether both codes match
    if ($user_code != $code) { 
        array_push($errors, "The codes do not match");
    } else {
        if (count($errors) == 0) {
            $query = "UPDATE user_database SET isConfirmed = true WHERE email = '$email'"; 
            mysqli_query($db, $query);
            $_SESSION['email'] = $email;
            header('location: user_details.php');
        }
     }
}