co.ador Posted December 17, 2009 Share Posted December 17, 2009 Hi guys I have a rating system that won't let users rate items which contain a single quote character within their string name: Item such as : Nike Air Force 1-Men's It would rate items with character such as in "Cotél" "popó" "Censáto" and so on but as I said before it won't INSERT character such as in item name "Men's " because of the single quote. Is that possible to add the single quote character to the encoding in use? So far i have don't all of the steps below to make it work with not results... the character encoding used is utf8, I find strange this character ecoding won't have a single quote inside their character set. 1- Once I have connected to the DB, I have use mysql_set_charset() as below <?php <?php header('Content-type: text/html; charset=utf-8');?> <?php require("constant.php"); $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if(!$connection){ die("Database connection failed:" . mysql_error()); } mysql_set_charset('utf8',$connection); $db_select = mysql_select_db(DB_NAME, $connection); if(!$db_select){ die("Database selection failed: " . mysql_error()); } ?> 2- I have Explicitly sent an HTTP Content-Type header with UTF-8 as in below <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link type="text/css" href="stylesheets/main.css" rel="stylesheet" media="all" /> 3-I have made sure that the encoding of the files itself is UTF-8 For saving the file in utf8 I have used dreamweaver CS3, went to Modify--- page properties--- title/encoding category---- and reload... After all this modification and applications still the database won't recieve any data which contain any of those types of characters, Any other suggestion Thank you... Link to comment https://forums.phpfreaks.com/topic/185517-help-with-an-encoding-issue/ Share on other sites More sharing options...
Kieran Menor Posted December 17, 2009 Share Posted December 17, 2009 Do I smell unescaped query data. Try escaping the string with addslashes() or mysql_real_escape_string(). Link to comment https://forums.phpfreaks.com/topic/185517-help-with-an-encoding-issue/#findComment-979461 Share on other sites More sharing options...
greatstar00 Posted December 17, 2009 Share Posted December 17, 2009 so, what is your code on insert into database Link to comment https://forums.phpfreaks.com/topic/185517-help-with-an-encoding-issue/#findComment-979463 Share on other sites More sharing options...
co.ador Posted December 17, 2009 Author Share Posted December 17, 2009 I hope it is the cases of addslashes() because i have already used mysql_real_escape_string() The script below is the Insertion point Where the data from the rating system is place into the database. This is an object oriented programing used by Cpradio creator of this rating system found in http://www.search-this.com/2007/06/04/css-the-star-matrix-pre-loaded-part-2/. <?php if (Rating::CheckRatingsByIp($varItem) == 0) { $ipAddress = $_SERVER['REMOTE_ADDR']; $varItem = mysql_real_escape_string($varItem); Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())", "InsertRating"); mysql_real_escape_string($varItem); Database::FetchResults("InsertRating"); Database::FreeResults("InsertRating"); Database::RemoveSavedResults("InsertRating"); // Information for the Output $averageStars = Rating::CalculateAverageRating($varItem); $newClassNames = "rated " . Rating::ShowStars($averageStars); } } ?> i have used it twice not sure where mysql_real_escape_string() function should go below or above he INSERT query.. Link to comment https://forums.phpfreaks.com/topic/185517-help-with-an-encoding-issue/#findComment-979475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.