Jordyn Jordyn - 6 months ago 66
MySQL Question

Cannot insert zero in to MySQL INT NULL

I have a query that save zero in one of the MySQL column.

Column was set to be

NULL
= no and
Default
= none. But my query wasnt working when i had that structurer when I save 0. So i change the value to null. But when saving 0 (zero) in database its still getting saved NULL.

When i had the column set to be
NULL
= no and
Default
it was working fine on my localhost but in my hosting query wasn't getting inserted. that is why i change it to null.

MySQL version 5.6.30

Query

$mysqli->query("INSERT INTO categories(cname, cat_description, cat_ parent) VALUES ('$cname', '$description', '0')");

Answer

You are actually trying to insert a string in an integer column. MySQL does not accept this. And it shouldn't.

Insert an integer:

$mysqli->query("INSERT INTO categories(cname, cat_description, cat_ parent) VALUES ('$cname', '$description', 0)");

Just remove the quotes around 0.

Comments