I am missing something due to to much partying I guess, but I have a small search script that works locally using wamp but when I throw it out on the internet, it works with latin characters but does not with Greek even though everything is xhtml and utf-8.
Not working maybe too extreme. The search is working with latin characters, e.g. if I type New York it works, but when I type Γρηγορίου it does not return values for the search.
On my local wamp the script works correctly and the database table is exactly the same and set to utf-8 in both cases.
I have just looked at phpinfo to compare settings for multibyte and they are the same.
do you set client encoding in your php scripts? set names query for example?
What did you do to you ensure that your data and database encoding set to utf8?
ini_set('display_errors','On');
error_reporting(E_ALL | E_STRICT);
mb_internal_encoding("UTF-8");
ini_set('auto_detect_line_endings', 1);
date_default_timezone_set('Europe/Athens');
test_db_connect()
or die ("Δεν είναι δυνατή η σύνδεση με τον διακομιστή, παρακαλώ ξανά δοκιμάστε σε άλλη στιγμή.
<br /> Cannot connect to server, Please try again at another time.<br /> \
");
mysql_query("SET NAMES 'UTF8'");
mysql_query("SET CHARACTER SET 'utf8'");
print "<form action=".$_SERVER['PHP_SELF']." method=\\"post\\">\
";
print "<td>\
";
print "<input name=\\"title\\" size=\\"60\\" maxlength=\\"200\\"><br />\
";
print "</td>\
";
print "</tr><tr>\
";
print "<td colspan=\\"2\\"> </td>\
"; // <hr>draw line
print "</tr><tr>\
";
print "<td colspan=\\"2\\" align=\\"center\\">\
";
print "<input type=\\"submit\\" name=\\"phrase\\" value=\\"- Search -\\" />";
// INPUT ERROR CHECKING BEGINS HERE
// alternate through variables, check for empty, validate
//-----------------------------------------------------------------------
if (!get_magic_quotes_gpc()) {
foreach ($_POST as $key => $value) {
// Assign to $temp and trim spaces if not array
$_POST[$value] = is_array($value) ? $value : addslashes(trim($value));
} // end foreach
} else {
foreach ($_POST as $key => $value) {
// Assign to $temp and trim spaces if not array
$_POST[$value] = is_array($value) ? $value : trim($value);
} // end foreach
} // end if (!get_magic_quotes_gpc
//This stops SQL Injection in POST vars
foreach ($_POST as $key => $value) {
$_POST[$key] = mysql_real_escape_string($value);
}
//This stops SQL Injection in GET vars
foreach ($_GET as $key => $value) {
$_GET[$key] = mysql_real_escape_string($value);
}
$keyword = $_POST['title'];
if (empty($keyword)) {
print "<br />\
";
print "<div align='center' class='red'>";
print "No keyword was entered to search for a book!";
print "<br /><br />\
";
gobackpage();
print "</div>";
print "<br /><br />\
";
die;
?>
</body>
</html>
<?
die;
}
// regular search
$select = "SELECT * FROM $db_name.$table_name
WHERE ( subject LIKE '%$keyword%' OR
author LIKE '%$keyword%' OR
isbn LIKE '%$keyword%' OR
city LIKE '%$keyword%' OR
title LIKE '%$keyword%' OR
owner LIKE '%$keyword%'
)";
$result = mysql_query($select) or die($errorinfo);
// display record
disp_recs();
I found the error. When I created the database for this, I forgot to change the encoding to general utf-8. As I checked the table encoding and found that it was correctly set to utf-8 I suddenly realized that I forgot to check the database.