0

in my mysql I have values with this special character: ½

When I try to fill a combo box with values from that column, I have "�" instead of "½".

This is my code:

 <meta charset="UTF-8">


<select name="loads" size=1>

<?php

$host = "xxxxxxxxx";
$username = "xxxxxxx";
$password = "xxxxx";
$database = "xxxxx";
$connection = mysqli_connect($host, $username, $password, $database); 
 
  if (mysqli_connect_errno()) { 
      echo "Database connection failed."; 
  }

    $query = "SELECT DISTINCT dist FROM mytable ORDER BY dist ASC ";
    $result = mysqli_query($connection, $query);

    while ($row = mysqli_fetch_assoc($result)) {
        echo "<option value=" . $row['dist'] . ">" . $row['dist'] . "</option>";
    }
    echo "</select> "
?>

How can I fix it, please?

Thank you

EDIT I deleted my table and created again using ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

I put this:

<head>
  <meta charset="UTF-8">
</head>

But I still have the same problem. Any advice?

  • 1
    The character encoding of your web page is `ISO-8859-1`. What is the encoding of the data in the database and the database connection? The most commonly used encoding, today, is `UTF-8`. – KIKO Software May 29 '22 at 14:12
  • I set UTF-8 but I still have the same problem. My database set character is utf8mb4_unicode_ci – marcello gabrielli May 29 '22 at 14:29
  • If you’ve changed the page’s meta attribute and it isn’t working, it is possible that there’s an HTTP header from the server that is overriding it still – Chris Haas May 29 '22 at 14:46
  • You do realize all the encodings have to be the same? So if you use `UTF-8` in the database, your page has to use `UTF-8` as well, not `ISO-8859-1`. – KIKO Software May 29 '22 at 15:23
  • I edited my post but I still have the same problem. – marcello gabrielli May 29 '22 at 15:27
  • @ChrisHaas I don't know how can verify HTTP header. Any advice, please? – marcello gabrielli May 29 '22 at 15:28
  • You can view the headers in the [browser developer tools](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools). Please see the explanation in the link. – KIKO Software May 29 '22 at 17:41

0 Answers0