How to get the result of a JSON in Ionic 3, but the echo result in PHP

1

I need to get the result of my JSON which can be "Registration already exists." or "Successful Registration." In my registration, I'm doing it this way:

submit(){

    var nome = this.data.nome;
    var celular = this.data.celular;    
    var email = this.data.email;
    var senha = this.data.senha;


    var link = 'http://localhost/webapi/cadastro_usuario.php?email='+email+'&nome='+nome+'&senha='+senha+'&celular='+celular;
     //var myData = JSON.stringify({email: this.data.email}) + JSON.stringify({senha: this.data.senha});

    this.http.get(link)
     .subscribe(data => {
         this.data.response = data["_body"]; //https://stackoverflow.com/questions/39574305/property-body-does-not-exist-on-type-response

         console.log(this.data.response);

         if(JSON.stringify(this.data.response) === "Cadastro já existe."){

          const alert = this.alertCtrl.create({
            title: 'Usuário Já Cadastrado',
            subTitle: 'Este usuário já se encontra cadastrado. Caso tenha esquecido seu cadastro, vá em "Esqueci a Senha".',
            buttons: ['OK']
          });
          alert.present();
        }

        if(JSON.stringify(this.data.response) === "Cadastro Realizado com Sucesso."){

          const alert = this.alertCtrl.create({
            title: 'Bemvindo',
            subTitle: 'Obrigado por se cadastrar. Seja bem vindo ao WellFit App. Faça seu login.',
            buttons: ['OK']
          });
          alert.present();
        }
     })
     }

My Console.log returns like this:

<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: telefone in C:\wamp64\www\webapi\cadastro_usuario.php on line <i>30</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>370752</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\webapi\cadastro_usuario.php' bgcolor='#eeeeec'>...\cadastro_usuario.php<b>:</b>0</td></tr>
</table></font>
Cadastro Realizado com Sucesso.

But in Postman returns normal, only messages.

How can I get the messages without this mess?

To complete my PHP it looks like this:

<?php

include './classes/conexao.php';
include './classes/DAO/UsuarioDAO.php';

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400');    // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
        header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    }

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
        header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
    }

    exit(0);
}

if ($_GET) {
    $email = $_GET['email'];
    $senha = $_GET['senha'];
    $nome = $_GET['nome'];
    $celular = $_GET['celular'];
    $telefone = $_GET['telefone'];

    $UsuarioDAO = new UsuarioDAO();

    $consulta = $UsuarioDAO->CadastraUsuario($email, $nome, $celular, $telefone, $email, $senha);

    if ($consulta == true) {
        echo 'Cadastro Realizado com Sucesso.';
    } else {
        echo 'Cadastro já existe.';
    }
}
    
asked by anonymous 24.07.2018 / 21:21

1 answer

1

Apparently it has the variable telephone, which should not be passed. Try to do something like this:

$telefone = isset($_GET['telefone']) ? $_GET['telefone'] : null;
    
24.07.2018 / 22:06