V
V
Vocler2019-09-16 17:54:31
Character encoding
Vocler, 2019-09-16 17:54:31

Where does the encoding error occur?

There is a form

<form accept-charset="UTF-8">
    <input type="hidden" value="Русский текст">
</form>
<button id="ajax">

There is a JS handler that, when the button is clicked, sends data to the server
$.post(
                "/handler.php",
                {
                    data : $('input').val()
                }
            );

There is handler.php
echo mb_detect_encoding($_POST["data"]); //Тут выводит UTF-8
$mysqli = new mysqli( *Тут данные* );
//$mysqli->query('SET NAMES "utf8"'); //Если расскоментировать эту строку все работает
$mysqli->query('INSERT INTO table (my_column) VALUES (data)');

All three files are encoded in UTF-8. Database and table encoding - UTF-8, comparison mode - utf8_general_ci. However, PHPMyAdmin shows gibberish. If you copy this gibberish into a text editor and convert windows1251->utf8 then the text becomes normal.
Where is the text generally converted to windows1251 if the UTF-8 encoding is set everywhere?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2019-09-16
@ThunderCat

//$mysqli->query('SET NAMES "utf8"'); //Если расскоментировать эту строку все работает

- Doctor, when I do this, it hurts!
- Don't do that.
The connection between the base and the puff goes according to its own protocol, chasing bytes of an unidentified type, and in order to understand what is being transmitted there, you need (surprise!) to indicate in what encoding these bytes are.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question