Answer the question
In order to leave comments, you need to log in
How to add NULL from PHP to MySQL DB?
Friends, tell me.
When trying to enter the database, an error occurs:
Incorrect integer value: '' for column 'nameN' at row 1.
The field type is INT, it is possible to add NULL.
SQL is trying to add something (not NULL), but not an int either.
I cannot rule this out. Changing just the type to int = 0 is also not an option, since for some id it exists and is logically important.
How to add NULL ? How to be?
$sql = "
INSERT INTO users_units
SET
`date`='$date',
`name1`='$array1[name1]',
`name2`='$array1[name2]',
........ ........
`name30`='$array1[name30],
ON DUPLICATE KEY UPDATE
`date`='$date',
`name2`='$array1[name2]',
........ ........
`name30`='$array1[name30]'
";
Answer the question
In order to leave comments, you need to log in
This is how it is written in SQL SET `name1` = NULL ...
, NULL - without quotes.
Always execute queries through prepared expressions only. This solves a LOT of problems right away, including your null pain.
As for automation, there are options, but it seems to me that in your case this liver sausage from name1 - name30 should be cut into pieces and written humanly in separate columns . And then there will be no problems automating requests.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question