php - Arabic text not storing in the mysql data base?

259

i have an mysql table member. member name has arabic names. mname collation set asutf8_general_ci.

when user enters arabic name its stores in the db table as some other characters. but when i retrieve and display it in the site, it displays correctly as Arabic text. why its not storing as arabic text in the database table ?

i tried this but only i am getting question marks no Arabic text...

1- MySQL charset: UTF-8 Unicode (utf8)

2- MySQL connection collation: utf8_general_ci

3- your database and table collations are set to: utf8_general_ci or utf8_unicode_ci

Then, add this code in your php script when you connect to db:

mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');

Php Code:

using simple php.

$mname = $_POST['mname'];
$email = $_POST['email'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$city = $_POST['city'];
$country = $_POST['country'];



$query="insert into member (mname, email, password, gender, age, city, country) values ('$mname','$email','$password', '$gender', '$age','$city','$country')";
mysql_query("SET NAMES 'utf8'"); 
mysql_query('SET CHARACTER SET utf8');
mysql_query($query);
318

Answer

Solution:

that could be problem with that to set meta tag

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

also you have to set column collection type it should be sameutf8_general_ci. more over table and database type will also consider as same.

And also some point to be carefull like

o read ,write and sort Arabic text in mysql database using php correctly, make sure that:

1- MySQL charset: UTF-8 Unicode (utf8)

2- MySQL connection collation: utf8_general_ci

3- your database and table collations are set to: utf8_general_ci or utf8_unicode_ci

Then, add this code in your php script when you connect to db:

mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');

for more details: LINK

let me know if i can help you more.

People are also looking for solutions to the problem: javascript - Does forcing file download with php headers affect my bandwidth?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.