-1

So I manually inserted data in my database using PHPMyAdmin on a wamp server. My database is in utf8_bin, my table is in utf8_bin and the column of the table is in utf8_bin. I added the menu name "Hébergement" (meaning hosting in french). While in PHPMyAdmin, the accents show as expected and the Data is readable with the accents.

When I load the menu name, instead of the accent I will get this: H�bergement.

Here's a resume of the PHP

$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
$query  = "SELECT * ";
$query .= "FROM category ";
$query .= "WHERE id = {$newSection}";
$sectionInfo = mysqli_query($connection, $query);
$section = mysqli_fetch_assoc($sectionInfo);
$output .= $section["name"];
echo $output;

If I replace the $output with $output = "Héberment"; the echo will display the accent so the problem is not from my HTML or my PHP.

Now if I UPDATE the field with the word written in plain text in a PHP page and then query its new content, it will display the accent. The problem is that now the "é" is replaced with "é" inside of PHPMyAdmin rendering my text unreadable.

Now since PHPMyAdmin is a web page, and it was able to display to me the accents correctly, there must be a way to query the tables content in the same way as PHPMyAdmin and have it show as accent, not "�" while keeping the content readable within PHPMyAdmin.

I am a beginner in the PHP and MySQL so let me know if you need more details.

Edit: To clarify, I took a screenshot of a line I partially editted in PHPMyAdmin (added the readable accent manualy) to illustrate the opposition of readability.

Here's a clear explaination of the situation

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Samuel Charpentier
  • 599
  • 1
  • 7
  • 28
  • Make sure you set the page's `charset` properly. – Barmar Feb 07 '17 at 11:53
  • Yes I have this right after my `` tag: `` – Samuel Charpentier Feb 07 '17 at 11:54
  • 2
    It needs to be in the `` section of the page, not right after the `` – baao Feb 07 '17 at 11:54
  • I just moved it to the `` and it still does the same thing, As I said, if i write it in plain text in my PHP doc, it will show correctly, its only when I query it from MySQL that it won't! – Samuel Charpentier Feb 07 '17 at 11:57
  • 1
    Please check this [mysqli_set_charset](http://php.net/manual/en/mysqli.set-charset.php). Use it while both writing and reading the data – user2890234 Feb 07 '17 at 12:08
  • If you're using UTF-8, then you need to make sure that every part of your system is using it. That means your DB, your PHP code, and the browser. If you've got the wrong encoding type anywhere in the chain, then you'll get broken characters being displayed, or worse. Try reading [this question on SO for a solid list of things to check](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through). – Simba Feb 07 '17 at 13:02
  • Yes great! I only needed to add `mysqli_set_charset($connection, 'utf8');` right after `$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);` It worked – Samuel Charpentier Feb 08 '17 at 11:48

1 Answers1

0

This does the trick thanks everyone

$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

mysqli_set_charset($connection, 'utf8');

$query  = "SELECT * ";
$query .= "FROM category ";
$query .= "WHERE id = {$newSection}";
$sectionInfo = mysqli_query($connection, $query);
$section = mysqli_fetch_assoc($sectionInfo);
$output .= $section["name"];
echo $output;
Samuel Charpentier
  • 599
  • 1
  • 7
  • 28