0

I created a table with the following sql:

CREATE TABLE fens_mng_people_utf8 (
  pidm varchar(16) NOT NULL default '',
  fname varchar(32) NOT NULL default '',
  mname varchar(32) default NULL,
  lname varchar(32) NOT NULL default '',
  KEY pidm (pidm)
)CHARACTER SET utf8
 DEFAULT CHARACTER SET utf8
 COLLATE utf8_general_ci
 DEFAULT COLLATE utf8_general_ci;

And some Turkish characters such as Ş appears as a html code Ş even if I insert it directly with an sql not from a text document. And I am viewing it from phpmyadmin.

As a result, when I try to do such operations in my php:

SELECT * FROM  fens_mng_people_utf8 WHERE fname = '$fname' and lname = '$lname'

It returns null because $fname and $lname both displays Turkish characters properly.

I either want to correctly display Turkish characters in my table or convert $fname as it would match the value in my database.

Thanks for the help!

deceze
  • 510,633
  • 85
  • 743
  • 889

2 Answers2

0

your schema looks fine. check this sqlfiddle. it returns correct row. try adding this before doing your actual query:

mysql_query("SET NAMES utf8");
Volkan Ulukut
  • 4,230
  • 1
  • 20
  • 38
0

The database does not convert anything to HTML entities, because the database has nothing to do with HTML. Unless you're doing it yourself with htmlentities(), the most likely explanation is that the browser is sending you encoded data because it cannot handle the character correctly otherwise. Why can't it handle the character otherwise? Because you have not instructed the browser correctly to use UTF-8. You need to set the Content-Type: text/html; charset=utf-8 HTTP header and/or set the <form ... accept-charset="utf-8"> attribute to make sure the form data is sent UTF-8 encoded.

If you do neither and the browser defaults to Latin-1, "Ş" cannot be encoded in Latin-1 and the only fallback for the browser is to send you HTML entities. See Handling Unicode Front To Back In A Web App.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • As I said, i inserted the data using phpmyadmin so I do not create any forms or use any php files that I created. But with your explanation, I got the idea that it might be caused by the phpmyadmin itself (which is a very old version) and the way they defined the form does not support utf8 correctly in that version.. Would you say that might be the case? Thanks by the way! – user3345638 Feb 24 '14 at 12:11