Mysql database cannot add NULL values-php Tutorial

Source: Internet
Author: User
Mysql databases cannot add NULL values for data verification, but cannot add NULL values for data. the following error is returned:
Column 'loumiandijia' cannot be null

Other data cannot be used if it is NULL.

The code is as follows:
 1) {$ city = mysqli_real_escape_string ($ conn, $ trimmed ['city']);} else {$ errors [] = '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 [] = 'publication date cannot be blank ';} else {$ fabu_time = mysqli_real_escape_string ($ conn, $ trimmed ['fabu _ time']);} if (empty ($ trimmed ['chengjiao _ time']) {$ errors [] = 'transaction date cannot be blank ';} else {$ chengjiao_time = mysqli_real_escape_string ($ conn, $ trimmed ['chengjiao _ time']);} if (empty ($ trimmed ['jiezhi _ time']) {$ errors [] = 'margin cutoff Time cannot be blank ';} 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 [] = 'enter a correct bidding deposit (10 million RMB )';} if (is_numeric ($ trimmed ['mianji _ m']) & ($ trimmed ['mianji _ m']> 0) {$ mianji_m = mysqli_real_escape_string ($ co Nn, (float) $ trimmed ['mianji _ m']);} else {$ errors [] = '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 [] = 'enter a correct footprint ';} if (is_numeric ($ trimmed ['guihua _ p']) & ($ trimmed ['guihua _ p']> 0) {$ gui1__p = mysqli_real_escape_string ($ conn, (float) $ trimmed ['guihua _ p']);} Else {$ errors [] = 'enter a correct planned building area ';} if (is_numeric ($ trimmed ['qipaijia']) & ($ trimmed ['qipaijia ']> 0) {$ qipaijia = mysqli_real_escape_string ($ conn, (float) $ trimmed ['qipaijia']);} else {$ errors [] = 'enter a correct starting price (10 thousand/acre) ';} $ 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; $ chilang_p = (! Empty ($ trimmed ['Church _ p'])? Mysqli_real_escape_string ($ conn, (float) $ trimmed ['Church _ 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 [] = 'SELECT whether the transaction is successful ';} if (empty ($ errors )) {$ q = 'Insert INTO f_tudi (tudi_id, city_id, weizhi, yongtu, rongjilv, midu, lvdi, fabu_time, chengjiao_time, jiezh I _time, baozhengjin, hour, mianji_p, gui1__p, qipaijia, hour, jingderen, chunang_p, dituweizhi, xuzhi, is_cheng) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '; $ Stmt = mysqli_prepare ($ conn, $ q); mysqli_stmt_bind_param ($ stmt, 'weight', $ tudi_id, $ city, $ weizhi, $ yongtu, $ rongjilv, $ midu, $ lvdi, $ fabu_time, $ chengjiao_time, $ hour, $ baozhengjin, $ mianji_m, $ mianji_p, $ gui1__p, $ qipaijia, $ hour, $ yijialv, $ jingderen, $ chilang_p, $ dituweizhi, $ xuzhi, $ is_cheng); mysqli_stmt_execute ($ stmt); if ($ stmt) = 1) {echo 'this data item has been added successfully'; $ _ POST = array ();} else {echo'

Program error. please add again

'; Echo'

'. Mysqli_stmt_error ($ stmt ).'

';} Mysqli_stmt_close ($ stmt) ;}} if (! Empty ($ errors) & is_array ($ errors) {echo'

The following error occurs:
'; Foreach ($ errors as $ msg) {echo "-$ msg
\ N ";} echo 'please try again

';}?>


Too many code points for development


Reply to discussion (solution)

Add land data

Set the field to not null.
$ Loumiandijia = (! Empty ($ trimmed ['loumiandijia '])? Mysqli_real_escape_string ($ conn, (float) $ trimmed ['loumiandijia ']): NULL;

Change
$ Loumiandijia = (! Empty ($ trimmed ['loumiandijia '])? Mysqli_real_escape_string ($ conn, (float) $ trimmed ['loumiandijia ']): '';
Try

Set the field to not null.
$ Loumiandijia = (! Empty ($ trimmed ['loumiandijia '])? Mysqli_real_escape_string ($ conn, (float) $ trimmed ['loumiandijia ']): NULL;

Change
$ Loumiandijia = (! Empty ($ trimmed ['loumiandijia '])? Mysqli_real_escape_string ($ conn, (float) $ trimmed ['loumiandijia ']): '';
Try


Field not set to not null
See the table below.

But I can write data to the database with another method. what is the problem?
If (empty ($ errors) {$ q = "insert into f_tudi (tudi_id, city_id, weizhi, yongtu, rongjilv, midu, lvdi, fabu_time, duration, expires, baozhengjin, mianji_m, metrics, gui1__p, qipaijia, metrics, jingderen, chunang_p, dituweizhi, xuzhi, is_cheng) VALUES ('$ tudi_id', '$ City ', '$ weizhi',' $ yongtu', '$ rongjilv', '$ midu', '$ lvdi', '$ fabu_time', '$ chengjiao_time', '$ jiezhi_time ', '$ baozhengjin', '$ mianji_m', '$ mianji_p', '$ gui1__p', '$ qipaijia', '$ Comment', '$ Comment', '$ loumiandijia ', '$ yjialv', '$ jingderen', '$ chunang_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 'The data has been added successfully'; $ _ POST = array ();} else {echo'

Program error. please add again

';}}


Another problem is that after I write data to the database, there are a lot of NULL values that are blank, but there is nothing in it. this is different from the one I showed in the tutorial, the NULL value in the tutorial is NULL. what is the problem?

It is null when you insert it. I think none of your table design can be null. If you input this parameter, an error is returned.

It is null when you insert it. I think none of your table design can be null. If you input this parameter, an error is returned.


By default, isn't it? How to set

The column of no indicates NULL. is it NULL? OK? No. You? NULL? Go? Why? Ah.

What's your new one ?? Method? Put null ?? '', So yes.

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.