Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP SQL query returns no results whenever an extended character (e.g. ó or ú) is used

  • 10-01-2011 12:01am
    #1
    Closed Accounts Posts: 4,001 ✭✭✭


    Hi all

    I hope someone can help me with this as I am finding it very confusing.

    I have a search form which works fine when I use normal English characters. However when I use Spanish characters no results are ever returned.

    For example, let's say I want to search for "Selección".

    The SQL I generate in PHP will look like this:

    [PHP]
    select * from table where (title like '%Selección%')
    [/PHP]

    If I run this SQL directly on the MySQL database it will return 1 result.

    However if I run it within PHP it will return no results.

    This is my code:

    [PHP]
    $query = "select * from table where (title like '%Selección%')";
    $result = mysql_query($query);
    [/PHP]

    As you can see, it's very simple.

    Do any of you have any ideas what could be causing this?

    Note I have tried adding the following but it makes no difference:

    [php]
    mysql_query("SET NAMES 'UTF8'");
    [/php]

    Thanks!


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Not sure if you'll need to set the encoding when you are querying data from PHP.

    [php]$DB->query("SET NAMES 'utf8'");[/php]

    http://www.shawnolson.net/a/946/unicode-data-with-php-5-and-mysql-41.html


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    By the way I'm not so sure you can literally write encoded chars like that in the source. May have to escape it with the unicode. I'm not sure, I never done unicode in PHP.


  • Closed Accounts Posts: 4,001 ✭✭✭Mr. Loverman


    Fixed it.

    htmlentities - which I use to sanatise user input - was converting the extended characters into different characters...

    Thanks for the assistance.


Advertisement