![](/img/trans.png)
[英]How to Insert NULL Value from PHP Variable to MySQL, staying away from SQL Injection?
[英]How to insert a null value from php variable to mysql
我想通过 php 变量将字段设置为 null 值。 我正在使用 Laravel eloquent。
if($request->sectionId=='NULL'){
$sectionId=NULL;
}else{
$sectionId=$request->sectionId;
}
$question= new Question;
$question->sectionid=$sectionId;
它返回给我错误:integer 值不正确:farsifor_m 列的“ farsifor_m
”。 questions
。 第 1 行的sectionid
(SQL:插入questions
( formid
、 questionType
、 order
、 sectionid
、 updated_at
、 created_at
)值(?、shortAnswer、1、NUll、2021-05-08 18:51:24、2021-05-08 18 :51:24))”
看来您在$request->sectionId
的值中有拼写错误 - 'NUll' 而不是 'NULL'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.