1

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 utf8_general_ci

  • Changed the table Collation to utf8_general_ci

  • 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

Waftrue A.
  • 13
  • 4
  • PhpMyAdmin does not store anything. However, even your browser settings might be wrong. You didn't tell how the input gets into the database, so there can be one to a hundred steps where it goes wrong. – dezso Oct 21 '16 at 15:56
  • Edited the question to make it more clear. @dezso – Waftrue A. Oct 21 '16 at 16:56
  • Try running this query right after the connection: `SET NAMES utf8` – Jehad Keriaki Oct 21 '16 at 17:35
  • Use `utf8mb4_unicode_ci` in your MySQL. You should also employ `mbstring_` in PHP as outlined in the link posted here: [This topic will solve your issue](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) . – Martin Oct 23 '16 at 12:35

1 Answers1

0

This fixed the problem.

if (!mysqli_set_charset($conn, "utf8")) {
    printf("Error loading character set utf8: %s\n", mysqli_error($conn));
    exit();
} else {
    printf("Current character set: %s\n", mysqli_character_set_name($conn));
}
Waftrue A.
  • 13
  • 4