I have input fields, but if the users leave it blank, i want to insert a null value to my database.
I request values like this:
$val1 = htmlspecialchars($_REQUEST["val"], ENT_QUOTES);
And then insert them to the DB:
INSERT INTO `table` ( `val1` , `val2` , `val3`)
VALUES ('$val1', '$val2', '$val3');
I have tried removing the ' around val1, val2, val3 - but then nothing gets inserted into the DB if there is no value. I have also tried something like this:
if (!empty($val1)) {
$val1 = "'".$val1."'";
} else {
$val1 = NULL;}
And then without the ' around the values - still no insert to the DB