I have an issue with ionic 3 when I post data from the form with words containing accents even with everything set to UTF-8 (vscode, php header and connection charsets, database UTF8).
When I click to post it, console.log displays the word correctly accented. But it gets back the word with special characters. What could be wrong?
<?php
define("HOST", "localhost");
define("USER", "root");
define("PASSWORD", "******");
define("DATABASE", "loginsystem");
define("CAN_REGISTER", "any");
define("DEFAULT_ROLE", "member");
define("SECURE", FALSE);
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$mysqli->set_charset('UTF-8');
?>
$data = json_decode(file_get_contents("php://input"));
if(property_exists($data, 'name') || property_exists($data, 'uname') || property_exists($data, 'celular') || property_exists($data, 'endereco') || property_exists($data, 'numero') || property_exists($data, 'bairro') || property_exists($data, 'cidade') || property_exists($data, 'cep') || property_exists($data, 'senha') || property_exists($data, 'confirmar')){
$name = $data->name;
$uname = $data->uname;
$celular = $data->celular;
$endereco = $data->endereco;
$numero = $data->numero;
$bairro = $data->bairro;
$cidade = $data->cidade;
$cep = $data->cep;
$senha = $data->senha;
$confirmar = $data->confirmar;
...
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import { ListPage } from '../list/list';
let url = 'http://localhost/loginsystem/users/insert.php';
let user_id: any;
let headers = new Headers(
{
'Content-Type' : 'application/json;charset=UTF-8'
});
let options = new RequestOptions({ headers: headers });
@IonicPage()
@Component({
selector: 'page-cadastro',
templateUrl: 'cadastro.html',
})
export class CadastroPage {
responseData: any;
userData = {"name": "", "uname": "", "celular": "", "endereco": "", "numero": "", "bairro": "", "cidade": "", "cep": "", "senha": "", "confirmar": ""};
console.log('Hello AuthService Provider');
}
ionViewDidLoad() {
console.log('ionViewDidLoad CadastroPage');
}
signup(){
console.log(this.userData);
this.http.post(url, this.userData, options).subscribe(data => {
this.responseData = data;
console.log(this.responseData._body);
},error => {
console.log("error");
});
}