My problem is inserting a null value when a post variable is empty . . .
In this simplified version I have created a table with 3 columns:
DROP TABLE IF EXISTS application
.value
;
CREATE TABLE application
.value
(
key
int(10) unsigned NOT NULL auto_increment,
value
char(3) default NULL,
value2
varchar(3) default NULL,
PRIMARY KEY (key
)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
Simplified version:
<?php
include("database_inc.php");
$value = "NULL";
$value2 = NULL;
$dbs = "application";
@ $db = new mysqli($hst, $usnm, $pwd, $dbs);
$query = "INSERT INTO value Values(null, '$value', '$value2' ) ";
if(!mysqli_query($db, $query)){
echo mysqli_error($db);
}
$db->close();
?>
The above code writes to the DB, but inserts the characters NUL instead of the value null into column 2 ($value) and nothing into column 3 ($value2).
IS NOTHING THE SAME AS NULL??
The DB Admin is insisting that inserting nothing is not the same as null.
I realize I could do two different INSERT statements based on IF, however the form has many fields, posts many variables, and the actual query is:
$sql = "INSERT INTO IU_NAME VALUES('$key', '$key', null, null, null, null, null, null, null, null, null, '$LAST_NAME', '$FIRST_NAME', '$MIDDLE_NAME', '$BIRTH_NAME', '$NEWID', null, null, null, '$SUFFIX', null, null, null, null, null, null, '$CURRENT_ADDRESS', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, '$NOTNULL', null, null, null, null)";
Any help is greatly appreciated!
Len