Jump to content

mysqli_sql_exception: Incorrect string value


Guldstrand
Go to solution Solved by requinix,

Recommended Posts

Can someone please help me with the following error:

Uncaught mysqli_sql_exception: Incorrect string value: '\xE3\x12N\x1C\xE3\xA0...' for column `trptreg`.`users`.`secret`


I've searched and tried everything, but i still get the above error when i try to save a hash in MySQL.
Here is the column "secret":
 

secret varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL

 

Link to comment
Share on other sites

  • Solution

"Incorrect string value" means you're trying to insert data that isn't valid for the column. In your case, the column is defined as utf8mb4 (aka UTF-8) but your string is not UTF-8.

If the value is binary data then do not use VARCHARs in the first place. Those are for character data. Use VARBINARY instead.
https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html

Either that, or you aren't supposed to be inserting raw binary data but either hex digits or a base-64 encoded version of the data...

  • Like 1
Link to comment
Share on other sites

9 hours ago, requinix said:

"Incorrect string value" means you're trying to insert data that isn't valid for the column. In your case, the column is defined as utf8mb4 (aka UTF-8) but your string is not UTF-8.

If the value is binary data then do not use VARCHARs in the first place. Those are for character data. Use VARBINARY instead.
https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html

Either that, or you aren't supposed to be inserting raw binary data but either hex digits or a base-64 encoded version of the data...

VARBINARY was the solution. ☺️

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.