Guldstrand Posted June 5, 2023 Share Posted June 5, 2023 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 Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted June 5, 2023 Solution Share Posted June 5, 2023 "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... 1 Quote Link to comment Share on other sites More sharing options...
Guldstrand Posted June 5, 2023 Author Share Posted June 5, 2023 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. ☺️ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.