I'm trying to mount an array, in php, that returns to my controller, because the render is displaying on the 'undefined' console, why?
Controller
.controller('usuarioCtrl', function ($scope, $http, $window, $location) {
$scope.salvaUsuario = function (usuario) {
var idCep = $window.localStorage.getItem('idCep');
usuario.idCep = idCep;
$http.post("http://localhost:8888/sistemas/webApps/ionic/vcApp/www/php/salvaUsuario.php", usuario).success(function (data){
console.log(data);
var ema = $window.localStorage.setItem("emailLogin", data.email);
//console.log(JSON.stringify(data));
if(data.cod === 1){
$location.path('/cadastraUsuario');
$scope.msgExiste = "Usuário já existente. Tente outro.";
}
});
$location.path('/page10');
}
})
PHP
<?php
header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,X-Prototype-Version,X- Requested-With');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');
include_once("conPDO.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($data);
$nome = $data->nome;
$usuario = $data->usuario;
$email = $data->email;
$senha = $data->senha;
$idCep = $data->idCep;
$nome = utf8_decode($nome);
$tipoUsuario = "C";
$verificaUsuario=$pdo->prepare("SELECT * FROM usuarios WHERE nome=:nome AND email=:email");
$verificaUsuario->bindValue("nome", $nome);
$verificaUsuario->bindValue("email", $email);
$verificaUsuario->execute();
$quant = $verificaUsuario->rowCount();
if($quant != 1){
$result = array([
'email' => $email
]);
$insereUsuario=$pdo->prepare("INSERT INTO usuarios (idUsuario, idCep, tipoUsuario, nome, usuario, email, senha) VALUES (?, ?, ?, ?, ?, ?, ?)");
$insereUsuario->bindValue(1, NULL);
$insereUsuario->bindValue(2, $idCep);
$insereUsuario->bindValue(3, $tipoUsuario);
$insereUsuario->bindValue(4, $nome);
$insereUsuario->bindValue(5, $usuario);
$insereUsuario->bindValue(6, $email);
$insereUsuario->bindValue(7, $senha);
$insereUsuario->execute();
echo json_encode($result[0]);
}else{
$result = array(
'cod' => 1,
);
echo json_encode($result);
return false;
}