I have an e-commerce website which is in polish and the product categories are stored in the database (in polish)
For some reason the special foreign characters are not displaying but only in certain parts of the website.
characters like ł, ą, ó and many more.
the thing is they display perfectly in the main body of the category page but they are also displayed down the left hand side of the page as an alternative navigation and it is this left side nav which they are not displaying correctly...they are showing up as ? or �
I have checked the table in the database and it is stored as utf8_general_ci
I have checked the "left-nav.php" file which is included in the page and it is encoded in UTF8.
I even checked the category page file even though it displays the characters correctly in the main body, and it is also saved in UTF8.
I have this line of code in my site header
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
I use HeidiSQL to manage my database and they are stored correctly in the database
am I missing something? and what can I do to fix this?
Why would special characters like these display correctly in some places but not others?
Here is the code for the top category in the left navigation
<?php
$sql = mysqli_query($con, "SELECT * FROM RAE_categories_pl WHERE categoryID = '".$category."'");
$result = mysqli_fetch_array($sql);?>
<div class="liSelect"><img src="images/arrowdown_off.gif" style="padding:0px; margin:0px -10px 0 0;float:right;"><a class="select" href="<?php echo "http://" . $_SERVER['HTTP_HOST']?>/products/<?php echo $result['categoryID'];?>"><?php echo $result['categoryName'];?></a></div>
<?php
$sql2 = mysqli_query($con, "SELECT RAE_sub_categories_pl.categoryName AS subCatName, RAE_sub_categories_pl.categoryID AS subCatID FROM RAE_sub_categories_pl INNER JOIN RAE_products_pl ON RAE_products_pl.subCategory = RAE_sub_categories_pl.categoryID AND RAE_products_pl.active = 1 WHERE RAE_sub_categories_pl.parentCatID = '$category' GROUP BY RAE_sub_categories_pl.categoryID");
while ($result2 = mysqli_fetch_array($sql2))
{?>
<div class="liul">
<div class="ulli">
<a href="<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/equipment/" . $category . "/" . $result2['subCatID'];?>"><?php echo $result2['subCatName']?></a>
</div>
</div>
Make sure, that you are using SET NAMES 'UTF8'
after connecting to MySQL in php scripts, generating bad characters:
$con=mysqli_connect("host", "user", "pw", "db");
if (!$con)
{
die('Failed to connect to mySQL: ' .mysqli_connect_errno());
}
/* change character set to utf8 */
if (!$con->set_charset("utf8")) {
printf("Error loading character set utf8: %s
", $con->error);
}
As the manual says:
SET NAMES indicates what character set the client will use to send SQL statements to the server... It also specifies the character set that the server should use for sending results back to the client.
For foreign language support make Collation of the database table's corresponding field to utf8_unicode_ci
Try to set column collation to: utf8_polish_ci
example:
some_field VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8_polish_ci',
those who are using mysql can add this line to their connect section to fix special character display issue
mysql_set_charset('utf8',$link);
for mysqli users it would be
mysqli_set_charset($link,"utf8");