mysql数据库不能添加NULL值,该怎么解决
程序员文章站
2022-05-22 08:31:28
...
mysql数据库不能添加NULL值
数据都验证了,但是不能给数据添加NULL值,报错如下:
其他数据在为空是用NULL都不行
代码如下
数据都验证了,但是不能给数据添加NULL值,报错如下:
Column 'loumiandijia' cannot be null
其他数据在为空是用NULL都不行
代码如下
require ('inc/config.php');
$page_title = '住宅数据添加-feige数据中心';
include ('inc/header.php');
require (MYSQL);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$trimmed = array_map('trim', $_POST);
$errors = array();
if (!empty($trimmed['tudi_id'])) {
$tudi_id = mysqli_real_escape_string ($conn, $trimmed['tudi_id']);
} else {
$errors[] = '地块编号不能为空';
}
if ( isset($trimmed['city']) && filter_var($trimmed['city'], FILTER_VALIDATE_INT, array('city' => 1)) ) {
$city = mysqli_real_escape_string ($conn, $trimmed['city']);;
} else {
$errors[] = '请选择区域';
}
$weizhi = (!empty($trimmed['weizhi'])) ? mysqli_real_escape_string ($conn, $trimmed['weizhi']) : NULL;
$yongtu = (!empty($trimmed['yongtu'])) ? mysqli_real_escape_string ($conn, $trimmed['yongtu']) : NULL;
$rongjilv = (!empty($trimmed['rongjilv'])) ? mysqli_real_escape_string ($conn, $trimmed['rongjilv']) : NULL;
$midu = (!empty($trimmed['midu'])) ? mysqli_real_escape_string ($conn, $trimmed['midu']) : NULL;
$lvdi = (!empty($trimmed['lvdi'])) ? mysqli_real_escape_string ($conn, $trimmed['lvdi']) : NULL;
if(empty($trimmed['fabu_time'])) {
$errors[] = '发布日期不能为空';
} else {
$fabu_time = mysqli_real_escape_string ($conn, $trimmed['fabu_time']);
}
if(empty($trimmed['chengjiao_time'])) {
$errors[] = '成交日期不能为空';
} else {
$chengjiao_time = mysqli_real_escape_string ($conn, $trimmed['chengjiao_time']);
}
if(empty($trimmed['jiezhi_time'])) {
$errors[] = '保证金截止时间不能为空';
} else {
$jiezhi_time = mysqli_real_escape_string ($conn, $trimmed['jiezhi_time']);
}
if (is_numeric($trimmed['baozhengjin']) && ($trimmed['baozhengjin'] > 0)) {
$baozhengjin = mysqli_real_escape_string ($conn, (float) $trimmed['baozhengjin']);
} else {
$errors[] = '请输入一个正确的竞买保证金(万元)';
}
if (is_numeric($trimmed['mianji_m']) && ($trimmed['mianji_m'] > 0)) {
$mianji_m = mysqli_real_escape_string ($conn, (float) $trimmed['mianji_m']);
} else {
$errors[] = '请输入一个正确的占地面积(亩)';
}
if (is_numeric($trimmed['mianji_p']) && ($trimmed['mianji_p'] > 0)) {
$mianji_p = mysqli_real_escape_string ($conn, (float) $trimmed['mianji_p']);
} else {
$errors[] = '请输入一个正确的占地面积';
}
if (is_numeric($trimmed['guihua_p']) && ($trimmed['guihua_p'] > 0)) {
$guihua_p = mysqli_real_escape_string ($conn, (float) $trimmed['guihua_p']);
} else {
$errors[] = '请输入一个正确的规划建筑面积';
}
if (is_numeric($trimmed['qipaijia']) && ($trimmed['qipaijia'] > 0)) {
$qipaijia = mysqli_real_escape_string ($conn, (float) $trimmed['qipaijia']);
} else {
$errors[] = '请输入一个正确的起拍价(万/亩)';
}
$chengjiaodanjia = (!empty($trimmed['chengjiaodanjia'])) ? mysqli_real_escape_string ($conn, (float) $trimmed['chengjiaodanjia']) : NULL;
$chengjiazongjia = (!empty($trimmed['chengjiazongjia'])) ? mysqli_real_escape_string ($conn, (float) $trimmed['chengjiazongjia']) : NULL;
$loumiandijia = (!empty($trimmed['loumiandijia'])) ? mysqli_real_escape_string ($conn, (float) $trimmed['loumiandijia']) : NULL;
$yijialv = (!empty($trimmed['yijialv'])) ? mysqli_real_escape_string ($conn, $trimmed['yijialv']) : NULL;
$jingderen = (!empty($trimmed['jingderen'])) ? mysqli_real_escape_string ($conn, $trimmed['jingderen']) : NULL;
$churang_p = (!empty($trimmed['churang_p'])) ? mysqli_real_escape_string ($conn, (float) $trimmed['churang_p']) : NULL;
$dituweizhi = (!empty($trimmed['dituweizhi'])) ? mysqli_real_escape_string ($conn, $trimmed['dituweizhi']) : NULL;
$xuzhi = (!empty($trimmed['xuzhi'])) ? mysqli_real_escape_string ($conn, $trimmed['xuzhi']) : NULL;
if ( isset($trimmed['is_cheng']) && is_numeric($trimmed['is_cheng']) && ($trimmed['is_cheng'] >= 0) ) {
$is_cheng = mysqli_real_escape_string ($conn, $trimmed['is_cheng']);;
} else {
$errors[] = '请选择交易是否成功';
}
if (empty($errors)) {
$q = 'INSERT INTO f_tudi (tudi_id, city_id, weizhi, yongtu, rongjilv, midu, lvdi, fabu_time, chengjiao_time, jiezhi_time, baozhengjin, mianji_m, mianji_p, guihua_p, qipaijia, chengjiaodanjia, chengjiazongjia, loumiandijia, yijialv, jingderen, churang_p, dituweizhi, xuzhi, is_cheng) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';相关文章
相关视频
推荐阅读
-
ipad不能添加163邮箱账户该怎么解决?
-
添加数据后数据库里什么都没有,该怎么解决
-
mysql_query($sql)到底返回boolen值还是resource id?该怎么解决
-
mysql_query($sql)到底返回boolen值还是resource id?该怎么解决
-
phpMyAdmin不能连接到mysql上,该怎么解决
-
mysql 添加数据后在数据库里的排序,该如何解决
-
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
-
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
-
mysql_query($sql)到底返回boolen值还是resource id?该怎么解决
-
php添加到数据库表,该怎么解决