Michael Zelensky
Michael Zelensky

Reputation: 2132

HTML Form data > PHP > MySQL UTF encoding (cyrillics)

Problem: Cyrillic, UTF-8 encoded string, for example, "Михаил", specified in an HTML form, saved by PHP into MYSQL turns to unreadable krakozyabras like "Михайлович".

This is now a new problem, but I have found no solution so far... Please help if someone encountered this before.

HTML page is UTF-8 encoded and has properly set META; saving PHP script is UTF-8 encoded (with, or without BOM - doesn't matter). MySL table has DEFAULT ENCODING utf-8:

CREATE TABLE `cms_deposit_request` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

Any input welcome! Thanks!

Upvotes: 1

Views: 357

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157892

Always call

mysql_set_charset('utf8');` 

function (or a similar function from the API you are using) right after connecting to database

if there is no such function, run

SET NAMES utf8

SQL query in the same place

Upvotes: 1

Related Questions