Hi

I've set up a simple interface for a client where he can update the content of his homepage.

The text filed is set as longtext with collation of utf8_general_ci.

When I insert farsi/persian text in the field, it gets inserted in mySQL in very weird characters like this:

به سایت رسمی گروه موزیک « شن » خوش آمدید. 

The pages are all set in utf-8 encoding.

The problem seems to be with the mysql_query function.

the code I have is:

$sql2="UPDATE blog_fa SET welcome_text = '".mysql_real_escape_string($_POST['text_fa'])."' WHERE id ='$_POST[fa_id]'";
$update2=mysql_query($sql2);

I used var-dump on $sql2 and it shows the correct formatting, but something happens when data gets inserted . I read the manual on mysql_query didn't find the solution.

Also, sometimes I see the characters displayed as question marks, like ?? ???? ???
any ideas on that?

your help is GREATLY appreciated as I'm totally stuck!

tx
Kamy

    See this MySQL manual page which talks about the character set used when a client connects to the server.

    It's likely that you need to issue a SET NAMES 'utf8'; query upon connecting and before you send any UTF-8 encoded data.

      add

      mysql_query("SET NAMES 'utf8');

      after your connection

        thanks!

        this seems to have solved it!

          Write a Reply...