Sunday, February 20, 2022

[FIXED] Problem with the integer value in an SQL syntax: #1366 error

Issue

I was making a php website with some forms that let you make a form which let's you make an account, but for some reason when I was checking the SQL I was using inside phpmyadmin...

The SQL code it gave me an error that of

#1366 Incorrect integer value

Here is the SQL code I was checking:

INSERT INTO Users VALUES ('','$username','$password','0','empty')

The weird thing about this is the fact that the integer ID, which is in auto-increment, as I've learned it should be blank in the syntax like I've done (the ID column is the first one in my table)


Solution

When you are inserting rows into a table, the best practice is to always list the columns:

INSERT INTO Users (col1, col2, col3, col4)
    VALUES ('', '$username', '$password', '0', 'empty');

I don't know what your column names are, so you have to fill them in.

If you are writing application code, another best practice is to use proper parameters rather than munging a query string with values.



Answered By - Gordon Linoff

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.