I am traying to send special characters to a php server. I tried with angular and with jquery getting the same result:
myClient.js with JQuery:
data = "Ñoñón";
dataToSend={special_word: data};
$.ajax({
type : 'POST',
url : 'myServer.php',
data : dataToSend,
success : function(response){
console.log(response);
}
});
myServer.php for JQuery client:
$special_word =mysqli_real_escape_string($mysqli, $_POST["special_word"]));
saveWordInDB($special_word);
echo $special_word;
myClient.js with angular:
data = "Ñoñón";
dataToSend={special_word: data};
$http.post('myServer.php', dataToSend)
.then(
function(response){
// success callback
console.log(response.data);
},
function(response){
// failure callback
console.log(response);
}
);
myServer.php for angular client
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$special_word = $request->special_word;
saveWordInDB($special_word);
echo $special_word;
In both cases, the word "Ñoñón" is not stored in the DB, but the word "ñoñón" its stored instead. The same occurs with the word showed in the console. How can this be fixed?
Thanks in advance!