0

I have this part of code that works fine only the arabic issue.

$result = mysql_query("SELECT login, password, name, role FROM qm_users WHERE login = '$login'");

if (!$result) {
    die('Invalid query: ' . mysql_error());
}
$row = mysql_fetch_array($result);
echo $row["name"];

The name row contains arabic name.

The output of echo is ???? ???? ????

In my myphpadmin of xamp server, here the structure

enter image description here

  • have you tried adding a header at the top before any out put with the correct oncoding i.e header('Content-type: text/html; charset=UTF-8'); and adjust to the correct charset – Liam Sorsby Aug 13 '13 at 08:16
  • yes i ve added that: –  Aug 13 '13 at 08:18
  • no meta (html) is completely different to the header sent via php – Liam Sorsby Aug 13 '13 at 08:29
  • 1
    Also, stop using the old and deprecated `mysql_*` API. Use `mysqli` or `PDO` and [prepared](http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) [statement](http://www.php.net/manual/en/pdo.prepared-statements.php) + variable binding. – Passerby Aug 13 '13 at 08:31
  • @Passerby well spotted completely overlooked that! – Liam Sorsby Aug 13 '13 at 08:33

2 Answers2

2

Check below possible solution,

1) Your table structure 'Collation' must be 'utf8_unicode_ci'.

2) Also try to set below thing in php file

ini_set('default_charset','utf-8');
mysql_set_charset('utf8');
header('Content-type: text/html; charset=utf-8');
Manish Chauhan
  • 595
  • 2
  • 7
  • 14
1

If you are going to save UTF8 encodings to your MySQL database first set your connection encoding to UTF8.

<?php
$connection = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
mysqli_set_charset($connection, "utf8");
?>