I have the following code:
$var1 = NULL;
$var2 = NULL;
$var3 = NULL;
$var4 = NULL;
/* (...) code for logical flow condition (...) */
/* After the code, only var1 is different
*/
// $var1 = "something"
$query = "INSERT INTO (...) VALUES ('$var1','$var2','$var3','$var4');
Here is the deal: All fields for all vars are unique. The problem with the code is that the database doesn't insert with "duplicate value for $var2,3,4" because it is inserting the vars as ' ' instead of NULL. I want the values to be NULL BUT mantain it all in a coherent query... in a kind of concatenation if you may say, as to not disrupt the easiness of my logical flow code...
I want
$query = "INSERT INTO (...) VALUES ('$var1','$var2','$var3','$var4');
To be
$query = "INSERT INTO (...) VALUES ('$var1',NULL,NULL,NULL);
instead of how it is:
$query = "INSERT INTO (...) VALUES ('$var1','','','');
So, how can I do this keeping the variables in the query, both when NULL and not NULL? Tyvm for your help