# Insert error

**URL:** <https://forum.infinityfree.com/t/insert-error/55671>\
**Category:** Hosting Support\
**Created:** [December 11, 2021, 6:01pm UTC](https://forum.infinityfree.com/t/insert-error/55671 "2021-12-11T18:01:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon12722479](https://forum.infinityfree.com/letter_avatar/anon12722479/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon12722479](https://forum.infinityfree.com/u/anon12722479)\
**Post date:** [December 11, 2021, 6:01pm UTC](https://forum.infinityfree.com/t/insert-error/55671/1 "2021-12-11T18:01:32Z")

</div>

Please help me…  
I have error, when i do insert to database… but when i do it from localhost there is no problem

when i do this :

```auto
"INSERT INTO `user` (`user_id`, `email`, `username`, `password`, `game_id`) VALUES('', '$email', '$username', '$password', '$game_id')"

```

There is an error : Incorrect integer value: ‘’ for column ‘user\_id’ at row 1

And when i do this :

```auto
"INSERT INTO `user` (`user_id`, `email`, `username`, `password`, `game_id`) VALUES(null, '$email', '$username', '$password', '$game_id')"

```

The error is : Data truncated for column ‘game\_id’ at row 1

So what should i do ?  
And btw sorry for my bad english…

---

<div class="post-metadata">

**Author:** ![YT\_Xaos](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/yt_xaos/32/45201_2.png) [@YT\_Xaos](https://forum.infinityfree.com/u/YT_Xaos)\
**Post date:** [December 11, 2021, 6:36pm UTC](https://forum.infinityfree.com/t/insert-error/55671/2 "2021-12-11T18:36:16Z")

</div>

> [@anon12722479](#):
>
> Incorrect integer value: ‘’ for column ‘user\_id’ at row 1

Instead of an empty string try and put an integer.

> [@anon12722479](#):
>
> Data truncated for column ‘game\_id’ at row 1

What data type is the column set to? And what data type are you inserting?

Also, in the future please remember that this isn’t Stackoverflow.

---

<div class="post-metadata">

**Author:** ![HELPINDIA](https://forum.infinityfree.com/letter_avatar/helpindia/32/5_5575768a8748004e209b776fc1b2916d.png) [@HELPINDIA](https://forum.infinityfree.com/u/HELPINDIA)\
**Post date:** [December 11, 2021, 6:51pm UTC](https://forum.infinityfree.com/t/insert-error/55671/3 "2021-12-11T18:51:03Z")

</div>

First of all this type of doubts should be asked in coding forums like stackover kind of sites for better solutions!

You can get various scenarios solution there if you have any coding error.

> [@anon12722479](#):
>
> There is an error : Incorrect integer value: ‘’ for column ‘user\_id’ at row 1

If the string value is assigned to PHP script, that too the empty string is assigned meanly then you will get the error code Incorrect integer value.

Behind this scenario, the script which is running tries to update or insert the row with the entry integer may be with values assigning it as default ( 0 or Null, AUTO\_INCREMENT) value.

> [@anon12722479](#):
>
> The error is : Data truncated for column

When you load data from file to a MySQL table, you might run into this error: Data truncated for column ‘column\_name’ at row # That error means the data is too large for the data type of the MySQL table column. So define length!  
Note:  
Your localhost SQL config ini file may be modified thats y It can run without any error!

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [December 12, 2021, 12:58pm UTC](https://forum.infinityfree.com/t/insert-error/55671/4 "2021-12-12T12:58:22Z")

</div>

Regarding your main question, I second what the others have already said:

If you have a column of type INT, it means you need to fill it with an integer value. If you then provide it with `null` or a string (even if the string value is a number), MySQL won’t accept it.

> [@anon12722479](#):
>
> but when i do it from localhost there is no problem

This might be due to a different database version or setting. “Strict SQL Mode” is a setting that comes to mind that could affect this. If you have this turned off on your local system, and it’s turned on the server, then your local database might accept invalid values but the server might not.

> [@HELPINDIA](#):
>
> First of all this type of doubts should be asked in coding forums like stackover kind of sites for better solutions!

Given that there was a difference in behavior between local development and our servers, I do think it’s fair to consider that maybe the databases here are not working correctly.

---

<div class="post-metadata">

**Author:** ![HELPINDIA](https://forum.infinityfree.com/letter_avatar/helpindia/32/5_5575768a8748004e209b776fc1b2916d.png) [@HELPINDIA](https://forum.infinityfree.com/u/HELPINDIA)\
**Post date:** [December 12, 2021, 1:13pm UTC](https://forum.infinityfree.com/t/insert-error/55671/5 "2021-12-12T13:13:07Z")

</div>

> [@Admin](#):
>
> Given that there was a difference in behavior between local development and our servers, I do think it’s fair to consider that maybe the databases here are not working correctly.

I aware of this! That is y I mentioned about SQL modified config ini also in my reply!

---

<div class="post-metadata">

**Author:** ![YT\_Xaos](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/yt_xaos/32/45201_2.png) [@YT\_Xaos](https://forum.infinityfree.com/u/YT_Xaos)\
**Post date:** [December 12, 2021, 3:22pm UTC](https://forum.infinityfree.com/t/insert-error/55671/6 "2021-12-12T15:22:29Z")

</div>

> [@Admin](#):
>
> If you have a column of type INT, it means you need to fill it with an integer value. If you then provide it with `null` or a string (even if the string value is a number), MySQL won’t accept it.

If you have a column type INT and has AUTO\_INCREMENT you **can** put NULL and it will increment the integer.

---

<div class="post-metadata">

**Author:** ![HELPINDIA](https://forum.infinityfree.com/letter_avatar/helpindia/32/5_5575768a8748004e209b776fc1b2916d.png) [@HELPINDIA](https://forum.infinityfree.com/u/HELPINDIA)\
**Post date:** [December 12, 2021, 4:02pm UTC](https://forum.infinityfree.com/t/insert-error/55671/7 "2021-12-12T16:02:43Z")

</div>

> [@YT\_Xaos](#):
>
> If you have a column type INT and has AUTO\_INCREMENT you **can** put NULL and it will increment the integer.

But I hope like admin says below sometime its won’t work coz of server setting.

> [@Admin](#):
>
> This might be due to a different database version or setting. “Strict SQL Mode” is a setting that comes to mind that could affect this.

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [December 13, 2021, 1:44pm UTC](https://forum.infinityfree.com/t/insert-error/55671/8 "2021-12-13T13:44:37Z")

</div>

> [@YT\_Xaos](#):
>
> If you have a column type INT and has AUTO\_INCREMENT you **can** put NULL and it will increment the integer.

Really? I personally would just exclude it from the column list in the INSERT statement so you can be sure MySQL will take the default value.

After all, if you have a column that’s nullable, but has a non-NULL default value, then it does matter. If you then provide `NULL`, I expect MySQL to store `NULL`, not the default value. If `NULL` then means “default value”, how would you ever set that nullable column to `NULL`?

But this might be a difference caused by server settings. If MySQL is configured to be more lenient, it would make sense to take the default value if you provide a NULL value where NULL is not allowed. But that’s just MySQL fixing your query error for you, rather than the way you’re supposed to do things.

---

<div class="post-metadata">

**Author:** ![system](https://infinityfree-forum-uploads.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/0/b024fd3fa88bae093c9576e55c2c94e33f890206.svg) [@system](https://forum.infinityfree.com/u/system)\
**Post date:** [December 20, 2021, 1:44pm UTC](https://forum.infinityfree.com/t/insert-error/55671/9 "2021-12-20T13:44:46Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
