MySQL database cannot add null values

Source: Internet
Author: User
The data is verified, but you cannot add a null value to the data, and the error is as follows:
Column ' Loumiandijia ' cannot be null

The rest of the data is null and empty.

The code is as follows
  1)) {$city = Mysqli_real_escape_string ($conn, $trimmed [' City ']);} else {$errors [] = ' Please select region ';} $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 [] = ' Publish Date cannot be empty ';} else {$fabu _time = mysqli_real_escape_string ($conn, $trimmed [' fabu_time ']);} if (Empty ($trimmed [' chengjiao_time '])) {$errors [] = ' deal date cannot be empty ';} else {$chengjiao _time = mysqli_real_escape_string ($ conn, $trimmed [' chengjiao_time ']);} if (Empty ($trimmed [' jiezhi_time '])) {$errors [] = ' margin cutoff time cannot be null ';} 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 [] = ' Please enter a correct bidding margin (million) ';} if (Is_numeric ($trimmed [' mianji_m ']) && ($trimmed [' mianji_m '] > 0) {$mianji _m = mysqli_real_escape_string ( $conn, (float) $trimmed [' mianji_m ']);} else {$errors [] = ' Please enter a correct floor space (MU) ';} if (Is_numeric ($trimmed [' mianji_p ']) && ($trimmed [' mianji_p '] > 0) {$mianji _p = mysqli_real_escape_string ( $conn, (float) $trimmed [' mianji_p ']);} else {$errors [] = ' Please enter a proper footprint ';} if (Is_numeric ($trimmed [' guihua_p ']) && ($trimmed [' guihua_p '] > 0) {$guihua _p = mysqli_real_escape_string ( $conn, (float) $trimmed [' guihua_p ']);} else {$errors [] = ' Please enter a correct plan area ';} if (Is_numeric ($trimmed [' Qipaijia ']) && ($trimmed [' Qipaijia '] > 0) {$qipaijia = Mysqli_real_escape_string ( $conn, (float) $trimmed [' Qipaijia ']);} else {$errors [] =' Please enter a correct starting price (Million/MU) ';} $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 [] = ' Please select whether the transaction was successful ';} if (empty ($errors)) {$q = ' INSERT into F_tudi (tudi_id, city_id, Weizhi, Yongtu, Rongjilv, Midu, Lvdi, Fabu_time, Chengjia O_time, Jiezhi_time, Baozhengjin, Mianji_m, mianji_p, Guihua_p, Qipaijia, Chengjiaodanjia, Chengjiazongjia, Loumiandijia, Yijialv, Jingderen, Churang_p, Dituweizhi, Xuzhi, Is_cheng) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; $stmt = Mysqli_prepare ($conn, $q); Mysqli_stmt_bind_param ($stmt, ' Iissssssssdddddddddsdssi ', $tudi _id, $city, $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); Mysqli_stmt_execute ($stmt); if (mysqli_stmt_affected_rows ($stmt) = = 1) {echo ' This data has been added successfully '; $_post = Array ();} else {echo ' 

The program has an error, please re-add

'; Echo '

' . Mysqli_stmt_error ($stmt). '

';} Mysqli_stmt_close ($stmt);}} if (!empty ($errors) && Is_array ($errors)) {echo '

The following error occurred:
'; foreach ($errors as $msg) {echo "-$msg
\ n ";} Echo ' Please try it again

';}? >


Code too many sub-development


Reply to discussion (solution)

Land Data Additions    

The field is set to NOT NULL.
$loumiandijia = (!empty ($trimmed [' Loumiandijia ']))? Mysqli_real_escape_string ($conn, (float) $trimmed [' Loumiandijia ']): NULL;

Switch
$loumiandijia = (!empty ($trimmed [' Loumiandijia ']))? Mysqli_real_escape_string ($conn, (float) $trimmed [' Loumiandijia ']): ';
Give it a try

The field is set to NOT NULL.
$loumiandijia = (!empty ($trimmed [' Loumiandijia ']))? Mysqli_real_escape_string ($conn, (float) $trimmed [' Loumiandijia ']): NULL;

Switch
$loumiandijia = (!empty ($trimmed [' Loumiandijia ']))? Mysqli_real_escape_string ($conn, (float) $trimmed [' Loumiandijia ']): ';
Give it a try


No setting field set to NOT NULL
You look at the table.

But I changed a way to write to the database, what is the matter?
if (empty ($errors)) {$q = "INSERT into F_tudi (tudi_id, city_id, Weizhi, Yongtu, Rongjilv, Midu, Lvdi, Fabu_time, Chengjia O_time, Jiezhi_time, Baozhengjin, Mianji_m, mianji_p, Guihua_p, Qipaijia, Chengjiaodanjia, Chengjiazongjia, Loumiandijia, Yijialv, Jingderen, Churang_p, Dituweizhi, Xuzhi, Is_cheng) VALUES (' $tudi _id ', ' $city ', ' $weizhi ', ' $yongt U ', ' $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 '); $r = Mysqli_query ($conn, $q) or Trigger_error ("query: $ q\n
MySQL Error: ". Mysqli_error ($conn)); if (mysqli_affected_rows ($conn) = = 1) {echo ' This data has been added successfully '; $_post = Array ();} else {echo '

The program has an error, please re-add

'; }}


Another problem is that I write to the database empty value of a lot of NULL but there is nothing, empty, and I look at the tutorial is not the same, the tutorial empty value is a null, what is the matter?

When you insert it is NULL, I see your watch design inside is not NULL you also passed in this will definitely error.

When you insert it is NULL, I see your watch design inside is not NULL you also passed in this will definitely error.


Does the default not work? How else to set

The column of No, that is, NULL, since null? You? NULL?

What's your new one?? The law, the null? , so it's possible.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.