Since years I've a simple question: How to set values to NULL and write NULL to MySQL?
$var = trim(mysqli_real_escape_string($_POST["input_from_user"]));
if(strlen($var) < 1) {
$newvar = NULL;
}
else {
$newvar = $var;
}
and:
INSERT INTO `table` (`var`) VALUES ('$newvar')
...alyways writes an empty value into MySQL-Table, but not NULL! Of course: The field "var" is declared to allow "NULL" in MySQL.