Baltas Posted April 10, 2013 Share Posted April 10, 2013 I have well known but quite difficult to sort out problem here. And yes I was searching on forum but those threads are old enough so I decided to create new post. So I built a website using WP and included html FORM in one page. When user fills the form (in his/her language) the values of the fields' go into MySQL database table reg_form. Everything works, the values are saved, BUT some characters (specific in that language) are not recognized. I tried a lot of different methods to solve this, but nothing can help. The strangest thing is that if you look at WordPress tables you can find those specific characters are recognizable but not in reg_form table which I created. I was trying to solve this problem and finally I decided to approach in somehow ridiculous way. I created NEW database, new tables, installed new wordpress, created new form etc. That‘s what I was doing: I used this suggestion first: http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/ Yes, my files are saved using UTF8 encoding (without BOM). Yes, meta tags are ok. Yes, the FORM uses accept-charset='UTF-8'. Yes, all tables in database use UTF8. Yes, server, database and tables collation is the same “utf8_general_ci”. Then I tried to insert in my code this: $conn = mysql_connect($server, $username, $password);mysql_set_charset("UTF8", $conn); Then I tried this suggestion link here: http://akrabat.com/php/utf8-php-and-mysql/ Then I tried to set Apache's AddDefaultCharset in .htaccess file using this link here: http://httpd.apache.org/docs/2.0/mod/core.html#AddDefaultCharset BUT… still the problem remains. I can’t see those specific characters properly – only weird hieroglyphic. Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/ Share on other sites More sharing options...
jazzman1 Posted April 11, 2013 Share Posted April 11, 2013 Just compare the status of collation. Example: SHOW TABLE STATUS FROM wp-database; AND SHOW TABLE STATUS FROM new-database; Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424032 Share on other sites More sharing options...
Baltas Posted April 11, 2013 Author Share Posted April 11, 2013 But what's the point of this? On the other hand, I use the same and the only one database which contains: WP tables and reg_form table. Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424167 Share on other sites More sharing options...
jazzman1 Posted April 11, 2013 Share Posted April 11, 2013 This doesn't make sanse to me. Can you show us the result of: SHOW TABLE STATUS FROM wp-database; Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424187 Share on other sites More sharing options...
jazzman1 Posted April 11, 2013 Share Posted April 11, 2013 What would happen if you try to insert lithuanian characters without filling the html form? <?php $conn = mysql_connect('host','user','password'); $db_name = mysql_select_db('wp-database', $conn); mysql_set_charset('utf8', $conn); $query = "INSERT reg_form (title,body) value ('Aciu. Ačiū', 'Sveiki atvyke Sveiki atvykę')"; $res = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424195 Share on other sites More sharing options...
Baltas Posted April 11, 2013 Author Share Posted April 11, 2013 Jazzman1, NOW I reinstalled (freshly) wordpress, created database using CREATE DATABASE db_name CHARACTER SET utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT COLLATE utf8_general_ci ; Then, I created table using this: CREATE TABLE reg_form( `id` int(11) NOT NULL AUTO_INCREMENT,`first_name` char(50) NOT NULL,PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Then I tried to fill the form field. Those strange hieroglyphic were saved. Then I tried your suggested method - to pass value straight from the code. STILL the same shit! : / Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424220 Share on other sites More sharing options...
DavidAM Posted April 11, 2013 Share Posted April 11, 2013 Also, make sure the HTML with the form specifies UTF-8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424225 Share on other sites More sharing options...
Solution Baltas Posted April 11, 2013 Author Solution Share Posted April 11, 2013 (edited) HOLLY S**T!! FINALLY! : ))))))))The problem was that I was using mysqli_ queries. Now I tried to change to mysql_ (notice the change!) queries and it worked!! Two weeks of haaaaard working and researches... Phew!Now who can explain me properly the reasons of this phenomena? : )) Edited April 13, 2013 by fenway profanity Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424226 Share on other sites More sharing options...
Baltas Posted April 11, 2013 Author Share Posted April 11, 2013 thanks everybody for trying to help me : )I'm still waiting for detailed explanation : )Cheers Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424227 Share on other sites More sharing options...
jazzman1 Posted April 11, 2013 Share Posted April 11, 2013 thanks everybody for trying to help me : ) I'm still waiting for detailed explanation : ) Cheers When you are using mysqli_set_charset() the first argument must be the link identifier unlike from mysql_set_charset(). Quote Link to comment https://forums.phpfreaks.com/topic/276796-utf8-lithuanian-characters-unrecognized-in-mysql-database/#findComment-1424242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.