Clarkeez Posted August 16, 2011 Share Posted August 16, 2011 Ok.. I'm building a CMS for my guild. One thing that is constantly bugging me and breaking my scripts is if someone enters a character such as ó,í,é etc. I've tried with php.ini has this -> default_charset = "utf-8" I've tried with SQL database and tables set to utf8->utf8_general_ci I've tried with <meta http-equiv="Content-type" value="text/html; charset=utf-8"> on every page load I've tried with SET NAMES utf8; on every SQL connection. The data needs to be stored in a mySQL db and stored in $_SESSIONs, the weird symbols keep breaking my scripts.. What do you guys do to solve this stupid problem? Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/ Share on other sites More sharing options...
Clarkeez Posted August 16, 2011 Author Share Posted August 16, 2011 Ok let me give you a better example of what I mean.. Example.. <?php $str = 'Cóòkíémònztr'; $_SESSION['name'] = $str; $q = $db->query(" INSERT INTO names (name) values ('".$_SESSION['name']."') "); ?> Then, when I look in the database, it looks like this.. CóòkÃémà Current settings .htaccess -> AddDefaultCharset utf-8 PHP.INI -> default_charset = "utf-8" HTML -> <meta http-equiv="Content-type" value="text/html; charset=utf-8"> MySQL -> I've tried both utf8_bin and utf8_general_ci Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258305 Share on other sites More sharing options...
xyph Posted August 16, 2011 Share Posted August 16, 2011 What happens when you pull the data out and echo it? Same nonsense? The following works fine for me <html> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head> <body> <?php $db = new mysqli('localhost','root','','db'); $str = 'Cóòkíémònztr'; $db->query(" INSERT INTO `test` (`name`) values ('".$str."') "); $r = $db->query('SELECT `name` FROM `test`'); while( $d = $r->fetch_assoc() ) echo $d['name'].'<br>'; /* TABLE DUMP CREATE TABLE IF NOT EXISTS `test` ( `name` varchar(20) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; */ ?> </body> </html> It shows up bad in PHPMyAdmin oddly enough, considering it should use the UTF-8 charset. Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258324 Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Author Share Posted August 17, 2011 If I echo the data I get Cóòkíém� Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258327 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 That's very odd, considering my code works perfectly, even when I change it over to $_SESSION['test'] = 'Cóòkíémònztr'; $db->query(" INSERT INTO `test` (`name`) values ('".$_SESSION['test']."') "); Try it on your machine perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258328 Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Author Share Posted August 17, 2011 Same thing Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258329 Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Author Share Posted August 17, 2011 What settings is your charset and collation on that db table your using? Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258330 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 I have my table dump included with my sample script. CREATE TABLE IF NOT EXISTS `test` ( `name` varchar(20) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Perhaps the actual PHP file isn't encoded in UTF? It's gotta be on your side somewhere, as my example works flawlessly over here. Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258338 Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Author Share Posted August 17, 2011 Are you using Xampp by any chance? Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258340 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 No, WAMP at home (tested working) and individual installs at work (tested working) Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258345 Share on other sites More sharing options...
Clarkeez Posted August 17, 2011 Author Share Posted August 17, 2011 jesus christ im just guna rewrite this project from scratch. it's always the STUPID things that get in my way QQ Quote Link to comment https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258348 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.