December 22nd, 2013, 04:25 PM
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:
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.
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 05:03 PM.
Reason: Changing the title
December 22nd, 2013, 07:23 PM
What happens if you change the above line to:
Originally Posted by PacaMama
December 22nd, 2013, 08:27 PM
1. what is the charset of the database/table
2. how is the data looking in your table?
December 22nd, 2013, 09:37 PM
I capitalized the UTF... There was no change.
Originally Posted by richpri
December 22nd, 2013, 09:49 PM
1. The database is set to utf8_unicode_ci. I plain UTF-8 is not available.
Originally Posted by paulh1983
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.
December 22nd, 2013, 09:59 PM
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:
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.
December 25th, 2013, 08:09 AM
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.
Originally Posted by Jacques1
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.