co.ador Posted August 13, 2009 Share Posted August 13, 2009 Hi guys I have a rating system that won't let users rate items which contain the following character within their string name: Quote: é, ', ñ, ú, ó é The header has this charset set up <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> I stored the special characters above manually in the database which is utf-8 The rating system use a INSERT similar to the one below if (Rating::CheckRatingsByIp($varItem) == 0) { $ipAddress = $_SERVER['REMOTE_ADDR']; Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())", "InsertRating"); Database::FetchResults("InsertRating"); Database::FreeResults("InsertRating"); Database::RemoveSavedResults("InsertRating"); // Information for the Output $averageStars = Rating::CalculateAverageRating($varItem); $newClassNames = "rated " . Rating::ShowStars($averageStars); } the above php code insert the rating data in the database but it won't insert niether rate those item names that contain special character sets. I know there is a incompatibility between the header charset=ISO-8859-1 and the database charset=utf-8 so when the rating try to insert the rating data of an item name containing one of the special character above coming from a charset=ISO-8859-1 configuration into the database charset= as utf-8 then something is happening which won't rate. or it might be another problem the real cause please help..... thank you... Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 13, 2009 Share Posted August 13, 2009 Why can you not set it to this? <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> All your characters will display properly, you have no need to re-encode them, and the rating system will successfuly work. You may want to use header('Content-Type: text/html; charset=utf-8'); alongside to make sure it's all one encoding. The browser uses the meta tag, not your code, so one's browser will convert the UTF to mojimbake... the é, ', ñ, ú, ó é you're seeing. Only switching all to UTF will fix this! Quote Link to comment Share on other sites More sharing options...
co.ador Posted August 13, 2009 Author Share Posted August 13, 2009 when i change to <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> Two things happen 1- won't display any of the characters é, ', ñ, ú, ó é and second the rating system won't rate even though the browser, php or mysql database is not displaying those character in the string name of the item... ahi ahi!!! <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <html> <head> <link type="text/css" href="../stylesheets/shoeswebpageprueba.css" rel="stylesheet" media="all" /> <title>shoestore</title> <script type="text/javascript" src="scripts/prototype.js"></script> <script type="text/javascript" src="scripts/rating.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script> $(function() { var default_image = $('td.largethumb img').attr('src'); $('table.smallthumbs a').mouseover(function() { $('td.largethumb img').attr('src', $('img', this).attr('src')); }); }); </script> </head> <body> </body> </html> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 13, 2009 Share Posted August 13, 2009 If this is a problem in your script I'm truly not sure. What I would recommend is using the PHP command utf8_encode() to make sure it's put in your database as UTF-8 and not ISO so it will display properly.. é, ', ñ, ú, ó é Do those not display at ALL, or come out as weird text? If they're not displaying at all, even if it's all UTF-8; then it's a problem with your script placing it in your database, because those characters should send. Double check the code that send to and from it to make sure it doesn't strip out UTF .... Quote Link to comment Share on other sites More sharing options...
corbin Posted August 13, 2009 Share Posted August 13, 2009 If you're not doing so already, you may need to do a SET NAMES query. mysql_query("SET NAMES 'utf8';"); (Or perhaps utf-8.) Quote Link to comment Share on other sites More sharing options...
co.ador Posted August 13, 2009 Author Share Posted August 13, 2009 Guys where am I looking to place this commands and functions within the script? the "PHP command utf8_encode() " and the "mysql_query("SET NAMES 'utf8';");" Thank you. Quote Link to comment Share on other sites More sharing options...
co.ador Posted August 14, 2009 Author Share Posted August 14, 2009 How do I mysql_query("SET NAMES 'utf8';");? The mysql_query below is what I use to display the item name which display like $result = mysql_query( $query, $connection); In the rating table the item name passes like Cot�l of Jordan Instead of Cotél help everything is set all the fields TEXT, VARCHAR, tables and database to utf-8 and utf-8_general_ci and still the problem persist. At the beggining it was displaying fine but then the second time I tried it didn't display. Right now is storing the rating data but is not displaying characters such as é, ', ó,í, ú, á etc..... <html> <head> <?php header('Content-type: text/html; charset=utf-8');?> <link type="text/css" href="../stylesheets/shoeswebpageprueba.css" rel="stylesheet" media="all" /> <title>NYhungry</title> <script type="text/javascript" src="scripts/prototype.js"></script> <script type="text/javascript" src="scripts/rating.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script> $(function() { var default_image = $('td.largethumb img').attr('src'); $('table.smallthumbs a').mouseover(function() { $('td.largethumb img').attr('src', $('img', this).attr('src')); }); }); </script> </head> <body> Quote Link to comment Share on other sites More sharing options...
co.ador Posted August 14, 2009 Author Share Posted August 14, 2009 More information ::: I have done a new database and it is rating now it is storing the rating data but look how... In the browser it display like Pesuas instead of pesuñas In the search bar it display like pesu�s it is storing in the database like Pesu�s 127.0.0.1 3 2009-08-14 and in the database the shoe name is pesuñas There should be something in the code which is not passing the data very well... Quote Link to comment 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.