0

I am building a Mysql database, holding details of owners and breeders of ponies, as well as details on the animals themselves. The information is updated and viewed via PHP. As part of this, I have pages where contacts are listed out, and other pages where contacts may be assigned (via dropdown) to an animal as either an owner or a breeder. The database connection is set in the header (called by function) and closed at the end of each query.

I noticed that some characters (e.g. É) were not being rendered properly (�) in the dropdown lists of contacts, but were fine in the list pages. Having looked into previous questons posed here (Special characters in PHP / MySQL) I set my table's collation to utf8_bin, and connect to the db via

<?php
$con = mysql_connect("localhost", "user", "pass");
mysql_select_db("db", $con);
mysql_set_charset('utf8',$con);
?>

This resolved the dropdown list issue perfectly - but the list pages are now causing trouble. (É is now É). My browser was set to Western ISO-8859-1, but even changing that to UTF-8 has not helped. Echoing out

$charset = mysql_client_encoding($con);
echo "The current character set is: $charset\n";

at the foot of the list returns uft8, as it should. My bam is boozled.

Any advice greatly appreciated!

(P.s. in anticipation: the language will be overwhelmingly English, but with some Irish Gaelic, and possibly some French & German too. I have also tried all of the above with the Latin1 encoding.)

EDIT:

To fix the problem:

  • set the charset for the connection ($con)
  • set the collation for the data in the table - by column, by table is not sufficient
  • made sure to declare the HTML charset in my header via meta tag.
Community
  • 1
  • 1
Eamonn
  • 1,338
  • 2
  • 21
  • 53

1 Answers1

0

I suspect that you list display code utf8-encodes the HTML somehow. Remove that utf8_encode calls there.

You might also be missing the encoding declaration in the HTML pages themselves, which is needed to tell the browser that the page has the specific charset.

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • You mean I need to specify the charset within the html of the list itself? – Eamonn Aug 02 '11 at 14:15
  • ....but then my dropdowns wont read correctly. Thats my problem - if I fix one, the other breaks! Do you suggest setting the charset locally (per page) rather than in the header? – Eamonn Aug 02 '11 at 14:22
  • I've also set the charset per column in my table, not just table-wide. – Eamonn Aug 02 '11 at 14:26
  • Then you are missing the encoding specification in your HTML file. – cweiske Aug 02 '11 at 14:26
  • Yep - `` in the header did the trick. I didnt realise it needed specifying there also! Thanks cweiske! – Eamonn Aug 02 '11 at 14:31