user188962
user188962

Reputation:

special characters wont be inserted into mysql table the right way

I have a mysql database which Im trying to submit values to through a php file from a form.

If I manually insert values to the table 'myTable' with special characters like the swedish åäö letters, it works fine.

But when I am trying to use 'INSERT INTO' after a form is submitted on my page, to insert values to the table, all special characters turn out weird... Like symbols...

All collations are set to utf-8-swedish!

NOTE1: If I echo the values 'POSTED' from the form submit, the special characters are shown proberly. So its not the php file or the form itself.

NOTE2: All documents are set to utf-8

Thanks

Upvotes: 0

Views: 542

Answers (3)

user188962
user188962

Reputation:

mysql_query("SET NAMES 'utf8'") or die(mysql_error()); 
mysql_query("SET CHARACTER SET 'utf8'") or die(mysql_error());

THIS FIXED IT!

Upvotes: 1

John Parker
John Parker

Reputation: 54445

Is the HTML doctype set to UTF-8 as well?

Also, have you checked the MySQL connection character set? (You can verify this with 'mysql_client_encoding' and set it with 'mysql_set_charset'.)

Irrespective, when you extract the data from the database and echo it does it display correctly?

Upvotes: 3

Eemeli Kantola
Eemeli Kantola

Reputation: 5557

Ensure with mysql_set_charset that the MySQL connection charset is UTF-8.

Upvotes: 1

Related Questions