0

In my .html document where the form is i have

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

in the .php file where i connect to the database i tried with

mysql_set_charset('utf8');   
// and 
// <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

and this:

header('Content-Type: text/html; charset=utf-8'); 

The database rows are with Collation: utf8_unicode_ci

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
Daniel
  • 1
  • Try replacing the special characters with ansi as shown in the following website: http://www.w3schools.com/charsets/ref_html_ansi.asp – Chris G Jan 17 '16 at 17:32
  • 1
    Possible duplicate of http://stackoverflow.com/questions/279170/utf-8-all-the-way-through# – Alastair McCormack Jan 17 '16 at 18:33
  • My issue is that when i send the cyrillic letters to the database i get something like this -> Изберет and not the letters – Daniel Jan 17 '16 at 18:34

1 Answers1

0

You were hoping for something like Избере? You have Mojibake. Probably this is what happened:

  • The bytes you have in the client are correctly encoded in utf8 (good).
  • You connected with SET NAMES latin1 (or set_charset('latin1') or ...), probably by default. (It should have been utf8.)
  • The column in the tables may or may not have been CHARACTER SET utf8, but it should have been that.

If you need to fix the data it takes a "2-step ALTER", something like

ALTER TABLE Tbl MODIFY COLUMN col VARBINARY(...) ...;
ALTER TABLE Tbl MODIFY COLUMN col VARCHAR(...) ... CHARACTER SET utf8 ...;

where the lengths are big enough and the other "..." have whatever else (NOT NULL, etc) was already on the column.

Unfortunately, if you have a lot of columns to work with, it will take a lot of ALTERs. You can (should) MODIFY all the necessary columns to VARBINARY for a single table in a pair of ALTERs.

Rick James
  • 135,179
  • 13
  • 127
  • 222