PHP, MySql and latin characters áéíóú and ñ PROBLEM

A phrase like this:
Probando acentos á é í ó ú
(That means "Trying accents á é í ó ú)

Ends up like this:
Probando acentos á é Ã* ó ú

everytime I tried to send the form info to the table.

The page is enconding in a UTF-8

what else can I check to fix the problem?

Which encoding is the page in, which contains the form?
Do you encode output to utf8, when retrieving it from the database?

to be honest with you… Im not sure of that… sorry… its the first time I run into this problem, I never used the encoding before. this is what Im doing.

The page that contains the form dreamweaver says that it is utf-8 in the page property tab.

Now when I hit submit in my for, using POST method it turns into those weird characters.

And I dont understand what you mean by “Do you encode output to utf8, when retrieving it from the database?”

How can I verify if my page its actually utf-8?

In the page source it say: <meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8” /> in both pages the form and the one for the script.

The meta-tag isn’t really important. It’s only used as a fallback, if the web server doesn’t specify a content-type header with the charset in it. And most web servers do. Try opening the page in Firefox and open the menu View > Character Encoding. The encoding, which is selected there, is the one, which your page is interpreted in.

The first step, is to get data from the browser, to the server. The rule is, that the browser sends data back, in the charset, it got data in. So if your page, containing the form, is in UTF-8, then the form will be submitted as UTF-8, to the server (The PHP script). If you want full UTF-8 support, this is what you want to happen, so make sure your page is served as UTF-8 (To find out how, see below).

PHP isn’t aware of UTF-8, so inside PHP, the input data will always be interpreted as ISO-8859-1. When UTF-8 is interpreted as ISO-8859-1, exotic characters take up two or more characters, resulting in the garbled data, you have. This is fine however (Hang on, if that sounds weird).

You now need to move the data into your database. The connection between PHP and the database, has an encoding property. Normally, it would be ISO-8859-1, which is native to PHP, but if you set the database connection to UTF-8, then the garbled data will be interpreted correctly by the database.
If you use MySql, you can set the encoding of the connection, with the following statements:


This just takes care of the communication between PHP and MySql. Internally in the database, you need to make sure, that the tables are capable of storing the characters, you’re feeding it. By default, MySql creates tables as latin1 (=ISO-8859-1). This means, that it can’t store characters outside the range of that charset. So change your tables encoding to UTF-8. (You’d probably want to change the collation to UTF-8 as well)

Next step is to get data out of the database correctly. Again, set the database connection to speak in UTF-8, and you should get a string back, where exotic characters take up multiple bytes (Looking garbled to PHP). If you print this out to the document, and tell the browser, that the page is in UTF-8, they should be interpreted correctly (Even if PHP doesn’t understand it).

To tell the browser, which charset to interpret your page in, put a header() call, specifying the charset in the content-type header. Like this:

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

You can also include a meta-tag with the same contents, in your document, but this is redundant. The browser will always trust the header over the meta-tag, if they aren’t equal.

If you did everything right, you should now see data correctly.

so far, I havent been able to figure out the problem. One thing I notice… the posted information from the form page DO get to the script as ñ, but when the variable it is INSERTED into the database table, it changes to that weirs A character… Hope that helps even more

I just saw your last mesage, I’ll be back as soon as I do all the things you specified there. Thanks alot…

Thanks alot man! I understood everything you said. And now its working.
Needed to learn how to use the SET, so I google it and find out that it is used something like this:

		$db = mysql_connect('localhost', 'user', 'pass');
		if (!$db) {
			die('Could not connect: ' . mysql_error());
	// Select the database
	// Make sure data is UTF*, that way database can see accents and stuff
		mysql_query("SET NAMES 'utf8'", $db);
		mysql_query("SET CHARACTER_SET 'utf8'", $db);

And thats pretty much all. Hope that help someone like kyberfabrikken helped me…

Once again Thanks man.