How do php return status?

0

Next. I am doing a validation with angular and php, for when a user is registered, be verified if such user and password already exist and is not registered again. I need the php to return some information to angular so that a message can be displayed if there is a user with the same data.

My php:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);

include_once("conPDO.php");

$pdo = conectar();

$data = file_get_contents("php://input");
$data = json_decode($data);

$nome = $data->nome;
$email = $data->email;
$senha = $data->senha;
$idCep = $data->idCep;
$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){

$insereUsuario=$pdo->prepare("INSERT INTO usuarios (idUsuario, idCep, tipoUsuario, nome, email, senha) VALUES (?, ?, ?, ?, ?, ?)");
$insereUsuario->bindValue(1, NULL); 
$insereUsuario->bindValue(2, $idCep); 
$insereUsuario->bindValue(3, $tipoUsuario); 
$insereUsuario->bindValue(4, $nome);
$insereUsuario->bindValue(5, $email);
$insereUsuario->bindValue(6, $senha);

$insereUsuario->execute();

}else{
   O que colocar aqui?
}

?>
    
asked by anonymous 11.02.2016 / 01:20

1 answer

1

One solution is to give a false return: return false :

else {
echo 'A conta já existe!'; 
return false;
}
If you do not want to include two records in the bank you do this, $quant != 1 returns true if it does not return false.

See if it helps you ...

    
11.02.2016 / 01:25