0

I have a dropdown list, which lists things that has french characters in it. Although I see characters like this: enter image description here

MySQL database is set to UTF-8. So, there is no problem in database. I've checked the database and characters are okay.

I also added these lines to my header.php but still doesn't work.

header('Content-Type: text/html; charset=utf-8');
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8">

What else should I do?

EDIT I can print french letters everywhere in the site but still dropdown doesn't work.

SOLUTION First of all, if you would like to use utf-8 in your site you should add this right after you connect to database:

mysqli_set_charset($connectionName, 'utf8mb4');

Second, you should also add this in your header tags:

<meta charset="utf-8">

That's all. After all these, my problem still wasn't fixed until I figure out my stupidity. I have header.php file, which is included on top of every page but there is another php file, which outputs dropbox options from database. So, this file don't need header.php at top. So, I had to add mysqli_set_charset($connectionName, 'utf8mb4'); specially for that page.

cyonder
  • 852
  • 1
  • 15
  • 36
  • and what about your connection? – Funk Forty Niner May 20 '15 at 16:06
  • This may fall as a duplicate, see http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Funk Forty Niner May 20 '15 at 16:07
  • No! Oh I read about it yesterday. Everybody forgets that =) Yes that might be the problem? But how do we do it? – cyonder May 20 '15 at 16:07
  • 2
    *"No! Oh I read about it yesterday. Everybody forgets that"* - Sorry, I wasn't at that meeting ;-) – Funk Forty Niner May 20 '15 at 16:08
  • @Fred-ii- this is how I connect: $dbConnection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die("Unable to connect to MySQL"); – cyonder May 20 '15 at 16:09
  • http://stackoverflow.com/a/279279/ from the link I already gave you. It shows you how to pass UTF-8 through your connection and query. and http://stackoverflow.com/a/30063664/ – Funk Forty Niner May 20 '15 at 16:10
  • @Fred-ii- looks like this isn't the problem. After I connect to database I added charset function; $dbConnection = open_connection(); mysqli_set_charset($dbConnection, 'utf8mb4'); And I also added meta tags too – cyonder May 20 '15 at 16:26
  • 2
    well, check to see if your file was indeed "saved as" an UTF-8 format. Far too many things can be contributing to its failure, and I mean *far too many*. – Funk Forty Niner May 20 '15 at 16:27

0 Answers0