9

I have this form:

<form method="post" enctype="multipart/form-data" accept-charset="UTF-8">

But when I submit an é character, it turns it into é.

Why doesn't this work? Yes, the MySQL database has all the character-sets set up correctly. (Database, tables.) If I manually put it in the database with Navicat it shows up fine on the webpage.

Also, I have tried the metatag, setting the content-type header, without success.

Codecat
  • 2,213
  • 3
  • 28
  • 39
  • How are you putting the form data into the database? Is your server side language preserving UTF-8? – Oded Sep 02 '10 at 07:37
  • Are you serving your page as UTF-8 when you display it back to the user? Check that your meta tags and headers match. – davidtbernal Sep 02 '10 at 07:38
  • All fields go through mysql_real_escape_string, and are then put in the database using this query: mysql_query("UPDATE `users` SET `Profile`='".$newProfile."',`Avatar`='".mysql_real_escape_string($avatar)."' WHERE `ID`=".$thisUser['ID']); – Codecat Sep 02 '10 at 07:38
  • notJim: the é also appears in the database itself, which means that the clients are not sending it correctly, and thus a problem with either HTML or PHP that's not doing it right. – Codecat Sep 02 '10 at 07:40
  • Please edit your question and add these details to the question, instead of a comment. – Oded Sep 02 '10 at 07:40
  • When you say "appears in the database itself", which mysql client are you using to see that? I've encountered issues with utf-8 values in various clients including Mysql Query Browser. If you select the value back into php, with utf-8 headers et al properlty set, does it display it garbled? – Fanis Hatzidakis Sep 02 '10 at 09:40

4 Answers4

9

In your HTML, add this meta tag:

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

Also add this PHP header at top of the script:

 header("Content-Type: text/html;charset=UTF-8");

[EDIT]:

One more tip is to save the file as UTF-8 without BOM encoding. You can use Notepad++ or any decent editor to do that.

shamittomar
  • 46,210
  • 12
  • 74
  • 78
2

Had the exactly same problem as mentioned above, tried everything mentioned. Try deleting enctype="multipart/form-data" and adding accept-charset="utf-8" from the tag. This was the solution in my case.

1

Ensure you have set your connection collation to utf8:

SET NAMES utf8
aularon
  • 11,042
  • 3
  • 36
  • 41
0

Add only accept-charset="character_set" in form. It is all!

accept-charset="character_set"
Ivan Pirus
  • 1,026
  • 11
  • 21