Skip to content
Advertisement

Connection failed: SQLSTATE[HY000]: General error: 1366 Incorrect integer value

Basically I’m trying to get an ID from a url and insert it into a database, initially I had an undefined variable error, so I looked around and I saw a few threads suggesting $id = ''; to remove this problem, from what I can determine it did, however I noticed it wasn’t inserting into my database so I wrapped it in a try to see if it gave me an error which it did, the error in full was

My code

Advertisement

Answer

By default the bindValue() assumes a string datatype. If you want to use something like INT you need to add that to the call.

You may also need to do this with :userId if that is also an INT

You should also check that the $id and $userId variables contain a value and it is an integer

I also note that you are inside a if ($_SERVER['REQUEST_METHOD'] == 'POST') block but are getting your $id from $_GET['id'] with a line that sets your $id to an empty string $id = ''; as a default? This could also be part of your problems!

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