HarPaddy wrote:but if search word through form value like
$query = "SELECT * FROM restarant_details WHERE rest_names like '%".$_REQUEST['searchword']."%'";
empty result set is coming for this. I am using character set as ' utf-8' for form page.
Ok, first of all you should
NEVER include strings from $_POST, $_GET, $_REQUEST, $_COOKIE, etc. directly in an SQL query (read about SQL injections).
Escape them with
mysql_real_escape_string().
Besides, it's better to use $_POST or $_GET explicitly, according to what method you specify, rather than $_REQUEST.
Then, despite of the form using utf-8 encoding, apparently something is still messed up (could be even your webserver, strangely enough, I've seen that before). So include the iconv conversion anyway (which only converts if necessary, and does nothing if the string is already proper utf-8).
So use this: (after using the set names / collation etc from above, which has to be done only once per script, before other queries)
Code: Select all
$s = $_POST['searchword'];
if ($s != iconv('utf-8', 'utf-8', $s)) $s = iconv('windows-1252', 'utf-8', $s);
$query = "SELECT * FROM restarant_details WHERE rest_names LIKE '%".mysql_real_escape_string($s)."%'";
It should now work, no matter whether you type in 'angels' or 'ANGELS' or 'ÅnGeLs', etc in the search form.