Waftrue A. Waftrue A. - 1 year ago 75
MySQL Question

A Problem Storing Arabic Chars in Database

I'm trying to make a registration form where people will take the link and enter their information, which then gets gets stored in the database. Unfortunately, when I try to enter information in Arabic using the form ,it gets stored in PhpMyAdmin as an unknown chars.
I have tried the following without success.

  • Set the default charset in the index as follows:

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

  • Set the default charset in the database handler page:

    $cfg['DefaultCharset'] = 'utf_8';
    $cfg['DefaultConnectionCollation'] = 'utf8_general_ci';

  • Changed the database Collation to

  • Changed the table Collation to

  • Exported as sql and edit the charset but I found it UTF-8 already.

  • Made sure that my browser unicode is set to UTF-8.

And that's an example on how it works:

<form action="signup.php" method="POST" class="form">
<input type="text" name="first"><br />
<input type="text" name="uid"><br />
<input type="date" name="dob"><br />


$first = $_POST['first'];
$uid = $_POST['uid'];
$dob = $_POST['dob'];

$sql = "INSERT INTO students (first, uid, dob)
VALUES ('$first','$uid', '$dob')";

$result = mysqli_query($conn, $sql);

And they're connected through a required file to connect to the db.

$cfg['DefaultCharset'] = 'utf_8';
$cfg['DefaultConnectionCollation'] = 'utf8_general_ci';

$conn = mysqli_connect("localhost", "root", "", "test2");

if (!$conn ) {
die("Connection failed: ". mysqli_connect_error());


No idea what's causing this and I need a fast fix.

Preview of the error

Answer Source

This fixed the problem.

if (!mysqli_set_charset($conn, "utf8")) {
    printf("Error loading character set utf8: %s\n", mysqli_error($conn));
} else {
    printf("Current character set: %s\n", mysqli_character_set_name($conn));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download