#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Character encoding error but it is declared already


    I understand there are many posts regarding this error:

    The character encoding of the HTML document was not declared.

    I originally had my html page set to:

    <meta http-equiv="Content-Type" content="text/html;charset=windows-1252" >

    Then I changed it to:

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

    I get the error either way. And now in addition, my french characters are not coming through properly.

    My html file calls a php file that contains a database connection and mysqli statements to $_POST data to it. Since the error in the console came from this php file, I added:

    $mysqli->set_charset("utf8");

    All my attempts at finding or correcting the problem has failed. I am new to this site. The other site I was working with do not like beginner type questions. I am sure this will be easy to fix but I can't to figure it out on my own.

    Thanks.

    -----
    Edit: I forgot to mention that all my code works perfectly on my local phpmyadmin connection and crashes live. snif!!!
    Last edited by PacaMama; December 22nd, 2013 at 04:03 PM. Reason: Changing the title
  2. #2
  3. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    106
    Rep Power
    4
    Originally Posted by PacaMama
    Then I changed it to:

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

    I get the error either way. And now in addition, my french characters are not coming through properly.
    What happens if you change the above line to:

    <meta charset="UTF-8">
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,002
    Rep Power
    376
    1. what is the charset of the database/table
    2. how is the data looking in your table?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by richpri
    What happens if you change the above line to:

    <meta charset="UTF-8">
    I capitalized the UTF... There was no change.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by paulh1983
    1. what is the charset of the database/table
    2. how is the data looking in your table?
    1. The database is set to utf8_unicode_ci. I plain UTF-8 is not available.
    2. The table holds invoice data, a mix of number and text fields. Each text field is set to utf8_unicode_ci and the number fields did not require me to set the character.

    My old mysql connection worked just fine but when I upgraded my new invoice, I switched to mysqli.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    the character encoding of an HTTP response is generally declared in the response headers from your server. That is, your Apache (or whatever you're using) must send a Content-Type header like this:

    Code:
    Content-Type: text/html;charset=utf-8
    Check the response headers with the developer tools of your browser. If the character set isn't declared at all, you have to add it in the server configuration.

    The meta element should also work, but it's rather problematic. It means that the browser has to go through the HTML before it's even able to figure out the content of the response. There are also some limitations (see the reference on encoding declarations from the W3C). As far as I know, the meta element is mostly for offline documents.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    the character encoding of an HTTP response is generally declared in the response headers from your server. That is, your Apache (or whatever you're using) must send a Content-Type header like this:

    Code:
    Content-Type: text/html;charset=utf-8
    Check the response headers with the developer tools of your browser. If the character set isn't declared at all, you have to add it in the server configuration.

    The meta element should also work, but it's rather problematic. It means that the browser has to go through the HTML before it's even able to figure out the content of the response. There are also some limitations (see the reference on encoding declarations from the W3C). As far as I know, the meta element is mostly for offline documents.
    I contacted my webhost. It's great. They have a chat service. I asked them to confirm the host name. In the end they found the source of the problem to be an extra } in my connection code. The entire thing had nothing to with character encoding error I was receiving in the console. They also directed me to the error log on their side. I didn't even know it existed. The error was clearly stated there.

    Although the solving did not happen here, it got me started in the right direction. Also, I am reading your post on properly setting up mysqli connection. I am following your advice in that post. No that I no longer have an extra } I should be able to modify the code per your recommendation. Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo