Turkish character issue in MYSQL

Hello,

I have a contact form which has some Turkish text inputs. Character liks “ş” “ı” “ğ” and “ç” are not displaying in my DB correctly. Instead I am getting bunch of weird characters. Meta charset is UTF8 o n the form page but I don’ t know what I am missing here. Any suggestions?

Thanks…

EDIT
Continued from
Foreign characters don't display properly in MYSQL

Maybe the character set used either the database, table and more particularly in the field do not match the chartset used on the page

This is what I have exactly:

On the page:
Form has "accept-charset=“UTF-8"”
and DB fields are set to "varchar(500)utf8_turkish_ci "

What can be the issue here? It is really frustrating…

In my PHP script I also have:

$headers = “MIME-Version: 1.0” . “\r\n” .
“Content-type: text/html; charset=UTF-8” . “\r\n”;
return mail($_MY_EMAIL_ADDRESS,$subject,$body,$headers);
}

Have you tried to insert some text with those characters in the table directly? I mean, from the command black screen

No I haven’t. I have just triple checked everything and it all seems normal. I have set the DB and all of its tables utf8_turkish_ci it is driving me insane…

What I would do is to try to test one by one… I would try to use the command prompt screen to insert a short text into the database. Then I would query it (from the same screen) and check if that looked OK.

No chance. I have tried every single solution I could find yet nothing worked. My current config is:

General Setting on PHP My Admin: Server Connection Collation: utf8mb4_turkish_ci
Meta Tag of the form page:
My PHP script: $headers = “MIME-Version: 1.0” . “\r\n” .
“Content-type: text/html; charset=UTF-8” . “\r\n”;
return mail($_MY_EMAIL_ADDRESS,$subject,$body,$headers);
}

All my tables and columns are also in utf8mb4_turkish_ci

Any other ideas what may be missing here???

Thanks…

Most probably the database connection is using a different charset.

Try calling this query right after you have connected to the database:

SET NAMES utf8;

Hello TheRedDevil,

I have tried it before but maybe I have made a mistake. Would you do me a huge favor and take a look at the attached file? I would really appreciate if you could quickly scan through the scripts and let me know what I am missing.

Many thanks…database .php (3.2 KB)

Hello,

I have solved the problem. It was the missing command in my.ini file. I have added these two lines at the end of the page and it solved the problem:

collation_server = utf8_unicode_ci

character_set_server = utf8

Great to hear!

Noticed one thing in your php file that you would want to update.

$value = mysqli_real_escape_string($value);

to

$value = mysqli_real_escape_string($this->connection, $value );

Also uploaded the updated file, note this also have the SET NAMES in the connection method as well.

database .php (3.4 KB)

Thanks. I will make the changes right now. Also, another forum member had suggested that I should use prepared statements, I guess that is really important for the security of the DB right? Currently but I am using mysqli to connect to the DB.

If you have the ability to start using prepared statements, I would recommend it. If not on this project, perhaps on the next one.

Glad that you sorted out your issues. I couldn’t check your file at work but It’s great that you firgured it out. Good job!

Hey, I am sort of familiar with the concept and since I have come this far I may as well implement it. It will take a while to put everything in its place but I will do it. Thanks for the reply.

Thanks molona. I finally figured it out and it was such a relief.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.