Reputation: 31
How to save text field input into mytable as utf8 encoded data, since textarea input automatically changing into utf8 encoded data,
Upvotes: 1
Views: 855
Reputation: 23700
Firstly, make sure that your database table is set to character set UTF-8.
Secondly, set the page your are submitting data from as UTF-8 with the following meta tag:
<head>
<meta charset="UTF-8">
</head>
Then when making your connection to the database you can execute the following query to set any subsequent queries to the UTF-8 character set too:
query("SET NAMES utf8");
See: SET NAMES utf8 in MySQL? and http://www.w3schools.com/tags/att_meta_charset.asp
Upvotes: 0
Reputation: 183
SET NAMES utf8;
That will set the next queries to be saved AS UTF-8. Execute it before your actual INSERT or UPDATE
Be warned that if the sending page has a different charset, it would lead to character encoding errors.
Upvotes: 1