0

i have an mysql table member. member name has arabic names. mname collation set as utf8_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);
user2490465
  • 33
  • 2
  • 7
  • Maybe the tool in which you see those "other characters" uses a wrong encoding? – Sirko Jul 02 '13 at 09:00
  • `...its stores in the db table as some other characters...` how do you know that? Are you using something like phpMyAdmin? – Axel Amthor Jul 02 '13 at 09:01
  • How are you checking the contents of the table? – Burhan Khalid Jul 02 '13 at 09:01
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – deceze Jul 02 '13 at 09:04
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Jul 02 '13 at 09:05
  • @AxelAmthor yes. using phpmyadmin. – user2490465 Jul 02 '13 at 09:50
  • if your application stores / shows arabic chars properly and phpMyadmin will not, you have a problem with your phpMyAdmin settings, but obviously neither with your DB nor your Application. – Axel Amthor Jul 02 '13 at 10:00
  • @Axel Nope, it typically points to a misconfigured database connection encoding from the inserting/reading PHP script, not phpMyAdmin. – deceze Jul 02 '13 at 10:07
  • @deceze: yep, probably. If phpMyAdmin is not showing UTF8 properly, I would start from there before fiddling around in my own PHP code anyway. – Axel Amthor Jul 02 '13 at 10:11
  • @user2490465: what if you edit / store / retrieve arabic chars directly in phpMyAdmin? Are they properly treated then? – Axel Amthor Jul 02 '13 at 10:13
  • @Axel No, again: phpMyAdmin is *probably* fine, it's *probably* showing what's actually stored in the database. The problem is typically (90%+ in my experience) that the data was inserted incorrectly. Read my above-linked article. – deceze Jul 02 '13 at 10:13

1 Answers1

-1

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 same utf8_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.

liyakat
  • 11,825
  • 2
  • 40
  • 46
  • where should i set these (1)- MySQL charset: UTF-8 Unicode (utf8) (2)- MySQL connection collation: utf8_general_ci ??? – user2490465 Jul 02 '13 at 09:47
  • you can set with php as well as mysql also, you can find syntax for same. – liyakat Jul 02 '13 at 10:00
  • @liyakat i dont get it. in 'member'table 'mname' collation set as utf8_general_ci. it shows mname correctly in the webpage. that shows the arabic characters. but the problem is in the phpmyadmin table the 'mname' field is not showing arabic charactersits showing some other chars.. i used only this . now tell me what should i do??? – user2490465 Jul 02 '13 at 10:17
  • what do you mean by `some other chars`? Probably it's hex? – Axel Amthor Jul 02 '13 at 10:19
  • @AxelAmthor i have seen these chars... شسب, لاشس, الال باسل – user2490465 Jul 02 '13 at 10:30
  • please go throw all steps again :( – liyakat Jul 02 '13 at 10:55
  • @liyakat i used these mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8'); now i it showing only ???? question marks in the mname field.... – user2490465 Jul 02 '13 at 11:02
  • is fields encoding to utf8_general_ci ? – liyakat Jul 02 '13 at 11:08
  • now, i saw only ???? question marks .. no Arabic characters. in the webpage also i see only question marks... – user2490465 Jul 02 '13 at 11:28