views:

51

answers:

5

Hi, I am trying to save some data(name, last name) in my forms with php and mysql. It's simple form like:

 <input type='text' name='first_name' />

And php gets it after submiting with:

$first_name = trim(mysql_prep($_POST['first_name']));

The problem is, that if I type characters in my languege(lithuanian), it won't save them and will change into others.. I set the language of my country, also charset in mysql is UTF-8

Any ideas where the problem is?

EDIT: The very strange thing just happened. It started working just after I deleted all the charset=utf8 and set names utf8 :) however, thanks to everyone

A: 

You must send header into browser with information about page in UTF-8 Encoding.

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

or

header('Content-type: text/html; charset=utf-8');
Svisstack
i do it with meta charset="UTF-8"
Adomas
setting it in the HTML is one thing, actually sending a UTF-8 document is another....
Bob Fincheimer
A: 
<meta http-equiv="content-language" content="en, lt">

The LT is for Lithuanian.

Liam Spencer
A: 

Probably it's the MySQL connection's fault. As robertbasic said,

As Jan said, read http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html You'll most likely need to execute query something like SET NAMES utf8 right after connecting to the database.

For more possible causes, check http://stackoverflow.com/questions/3021769/how-to-display-a-mysql-table-data-in-another-language-properly-in-php/3021908#3021908 (as robertbasic said twice).

MvanGeest
A: 

You need the meta charset="UTF8" and also you need your connection charset set to utf8. Execute mysql_query("set names utf8") after connecting to the server.

ceteras
A: 

three things

first: the page itself must be utf-8 encoded, that is make sure that the html has the following line in the head tag somwhere:

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

second: make sure that the encoding of the database and the tables is utf8

and third: after connecting to the database execute the following statement:

SET NAMES utf8;
Ramuns Usovs