如果input的值为空,我一直在尝试将 NULL 插入到我的数据库中
但我仍然插入empty and NULL string
这是我的代码
此代码返回空白
if (empty($_POST['caller'])){ $caller= NULL; }else{ $caller = mysqli_real_escape_string($con, $_POST['caller']);}
or this
$caller = mysqli_real_escape_string($con, $_POST['caller']);
$caller = !empty($caller_contact) ? "'$caller'" : NULL;
此代码返回NULL字符串
$caller = mysqli_real_escape_string($con, $_POST['caller']);
$caller = !empty($caller_contact) ? "'$caller'" : 'NULL';
or this
if (empty($_POST['caller'])){ $caller= 'NULL'; }else{ $caller = mysqli_real_escape_string($con, $_POST['caller']);}
查询
$sql_caller = "INSERT INTO `tblcall_info` VALUES ('','$save_inc_id','$call_time','$call_date','$caller','$caller_contact','$receiver','$device')";
我也尝试将'$caller'
更改为$caller
,但这是一个错误。
答案 0 :(得分:2)
您可以尝试这种方式:
从查询中删除单个被调用的逗号并将其设置为查询它肯定会对您有用
if (empty($_POST['caller'])){
$caller="NULL";
}else{
$caller=mysqli_real_escape_string($con, $_POST['caller']);
$caller="'$caller'";
}
$sql_caller = "INSERT INTO `tblcall_info` VALUES ('','$save_inc_id','$call_time','$call_date','$caller','$caller_contact','$receiver','$device')";
答案 1 :(得分:1)
在$ sql_caller字符串中尝试此方法:
INSERT INTO table_name (column1,column2,...) VALUES(value1,value2,...);
跳过专栏&它的值,您希望将其设置为NULL。