MySQL and PHP - insert NULL rather than empty string

 Method 1:

$query = "INSERT INTO uradmonitor (db_value1, db_value2) VALUES (".
    (($val1=='')?"NULL":("'".$val1."'")) . ", ".
    (($val2=='')?"NULL":("'".$val2."'")) . 
    ")";

Method 2:
INSERT INTO table VALUES ('', NULLIF('$date',''))

Method 3:

$intLat = !empty($intLat) ? "'$intLat'" : NULL;
$intLng = !empty($intLng) ? "'$intLng'" : NULL;

Comments

Popular posts from this blog

How to Turn Off Ads in uTorrent

Disable browser caching using a PHP header.