Skip to content
Advertisement

SQLSTATE[22007]: Invalid datetime forma

I try to save some data that it brings me from my view, which is a table, but I don’t know why it throws me that error with the insert. result of insert

this is my view: table of view

this is my controller:

Advertisement

Answer

id_tipo_venta seems to be an empty string which is apparently not valid.

You can try debugging what you get in :

Your database field expects to receive an integer. Therefore, using the intval() function can solve your problem.

Indeed, I think your code returns an alphanumeric string.

Therefore, the code below will return 0 in all cases if no version is returned (not set, string or simply null):

On the other hand, intval() will always convert to int, so a decimal will be converted, example :

If this is not the desired behavior, maybe you should think about changing your database type.

EDIT : Of course, you can also set the value as null if you prefer to 0. You must allow nullable values in your database.

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