You are here: Re: Foreign characters behaving oddly « PHP SQL « IT news, forums, messages
Re: Foreign characters behaving oddly

Posted by Matthew White on 07/17/07 18:33

Well, the AJAX script passes the string correctly, because the PHP script
picks it up without problem. The issue seems to be with MySQL (see
eisenstein's post above).

"Markus" <derernst@NO#SP#AMgmx.ch> wrote in message
news:469cedd6$1_1@news.cybercity.ch...
> Matthew White schrieb:
>> Hello,
>> I have a website that is supposed to grab a French word, and return the
>> English translation. The front-end has an AJAX script, that dynamically
>> POST's the value to the backend:
>>
>> function post() {
>> var string = document.getElementById("string").value;
>> var poststr = "string=" + encodeURI( string );
>> makePOSTRequest('dict.eng.php', poststr);
>> }
>>
>> Then the backend takes the script, and queries a database for 30 words
>> most like that word:
>>
>> $query = "SELECT * FROM dictionary WHERE fr like ('" . $string . "%')
>> ORDER BY fr LIMIT 30";
>> $query = mysql_query($query);
>>
>> If I enter in a word like "bonjour", the script returns the words that
>> are most like bonjour. A word with a special character, like "français",
>> will return no values, even though it is in the dictionary. The page is
>> in UTF-8, and the database, tables, and fields are all utf8_bin. Can
>> anyone please point me in the right direction?
>
> Your Ajax function does encodeURI( string ) - do you decode it somewhere
> before you do the database query? You can check this with
> var_dump($string).
>
> Anyway, as you do a POST request, I would actually try to go without
> urlencoding the string (this is needed with the GET method). Javascript's
> encodeURI()/decodeURI() and PHP's urlencode()/urldecode() may have
> different behaviours. I'd rather try to have your function send the data
> as UTF-8. In a normal form, this would be done with the
> accept-charset="UTF-8" attribute in the form tag; I don't know wether this
> also works when sending data with your method.
>
> HTH
> Markus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация