MySQL and PHP - insert NULL rather than empty string

后端 未结 9 1230
陌清茗
陌清茗 2020-11-28 03:34

I have a MySQL statement that inserts some variables into the database. I recently added 2 fields which are optional ($intLat, $intLng). Right now, if these values are not

9条回答
  •  自闭症患者
    2020-11-28 04:11

    your query can go as follows:

    $query = "INSERT INTO data (notes, id, filesUploaded, lat, lng, intLat, intLng)
          VALUES ('$notes', '$id', TRIM('$imageUploaded'), '$lat', '$lng', '" . ($lat == '')?NULL:$lat . "', '" . ($long == '')?NULL:$long . "')";
    mysql_query($query);
    

提交回复
热议问题