Jump to content

How to change some characters which user entered in search box, pls help


Recommended Posts

Hello,

First of all sorry for bad english :-)

 

I have some data in mysql database. Have also search box which works fine except for "special croatian signs". We have š,ž,č,ć,đ.

So, š and ž works also fine but ć, č đ doesn't work. I search a little bit and change unicode to UTF8, and also add three line in conn file:

 

mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION='utf8_unicode_ci'");
 
But still have nothing :-(
 
When I enter đ instead đ, search work fine. Also when i enter sql query in mysql, works fine. But thrue web search failed.
 
 
This is search code:
 
<?php
if (!empty($_REQUEST['term'])) {
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM table WHERE name LIKE '%".$term."%' OR proiz LIKE '%".$term."%'";
$r_query = mysql_query($sql); 
 
while ($row = mysql_fetch_array($r_query)){    
echo '<a href="2.php?id='.$row['id'].'">'.$row['name'].'</a>'; 
echo '<br /> Tel: '.$row['tel'];  
echo '<br /> Proiz: '.$row['proiz'];   
echo '<br /><br /><br /><br /> '; 
}  
}
?>

 

Is it possible to check and replace search term if user enter đ to replace it to đ and do the search?

 

Again appologize for bad english and lack of knowledge in php 

 

Thanks in advance

You have a much bigger problem. You are using obsolete insecure Mysql code that has been completely removed from Php.

 

You need to use PDO with prepared statements.

https://phpdelusions.net/pdo

Edited by benanamen

If you have to search by HTML entities (like đ), there's something seriously wrong with your application or your data.

 

Does the database itself contain those entities? Then you need to repair your data first. Make a backup and write a short script which reads the encoded text, decodes it and writes it back.

 

And, yeah, do use PDO. The 90s are over.

Jacques1, data in my database are ok (đ,č,ć)

 

This is very hard to believe. The application must be truly fucked up to mangle the literal input “đ” into a Unicode character. And it must be even more fucked up to not accept the original character.

 

Your claim that some characters work while other don't again indicates a data problem.

 

I strongly recommend you check specific data records directly in the database (not with PHP). That is, search for “đ” with your web form, then look up the found rows directly in the database.

 

If you can definitely confirm that the record is found despite not containing “đ”, we need to see your code. Is JavaScript involved?

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.