I have a table with answers like that:
_________________________
| id | correct | answer |
|____|_________|_________|
| 1 | 1 | اللَّيلِ |
|____|_________|_________|
| 2 | 0 | النَّهارِ |
|____|_________|_________|
I display these answers and then I submit one of them with Ajax:
const request = new XMLHttpRequest();
request.open('POST', 'submit.php', true);
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.responseType = 'json';
var data = 'answer=' + userAnswer;
request.send(data);
Then I check it against DB:
$answer = $_POST['answer'];
$correctAnswer = 'SELECT answer FROM answers WHERE correct = 1';
if ($correctAnswer == $answer) {
echo 'equal';
}else{
echo 'not equal';
}
On safari when I submit the correct answer I get 'not equal'. This is the submitted string from safari اللَّيلِ
. When I compare this string to the one in the DB they are not equal:
$userAnswer = 'اللَّيلِ';
$correctAnswer = 'اللَّيلِ';
if ($userAnswer == $correctAnswer) {
echo 'equal';
}else{
echo 'not equal';
}
I use utf-8
encoding for both HTML and DB connection:
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
$conn = new PDO("mysql:host=$servername;dbname=$db;charset=UTF8", $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
What's wrong? why the same record from DB is different?