Jump to content

character encoding issue with a rating system help


co.ador

Recommended Posts

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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 ....

Link to comment
Share on other sites

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>




Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.