Skip to content
Advertisement

NULL changes to 0 when added to the db

Ok I have tried everything I can think of, I couldn’t make it. I am creating some inputs like this:

And then when I get the $_POST I am checking if the input is 0 or “” and setting it to NULL.

And I am adding to the DB with this

But when the query runs, qty6 (for example) that is 0 or “” doesn’t insert as NULL in the DB but as 0, the table field is int (though it doesn’t really matter). Any ideas how to fix this? I am kinda stuck! enter image description here

I have tried (qty6 = $var) the query just stops there.

The structure does allow NULL as the default value is in fact NULL.

If I try ${‘qty’.$z} = ‘NULL’ ; this makes NULL a string so it wouldn’t help as the field value type for price is Float and for qty is Integer

Advertisement

Answer

Ok I figured it out, instead of using

I used with prepare like this

And it seems to be working, this way NULL doesn’t become a string for sure.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement