Result after update

1

Hello, I would like a value of 1 after a run in the database, for example

I have the function in php:

function registrar_pagamento( $pago, $registro ){
    require_once "../controller/class.registro_controller.php";
    $reg['registro'] = $registro;
    $reg['pago']   = $pago;
    $registro_Controller = new registro_controller();
    $teste = $registro_Controller->update( $reg );
    if( $teste )
        echo json_encode( array( "retorno" => 1 ) );
    else
        echo json_encode( array( "retorno" => 0 ) );
}

Do not give:

public function update ( $registro ){
        require_once "../include/error.php";
        require_once "class.connection_factory.php";
        $teste = false;
        $this->connection = new connection();
        $this->connection->beginTransaction();
        try{

            $sql = "UPDATE registro SET
                     SN_PAGO = :SN_PAGO
                    WHERE CD_REG_PESSOA = :CD_REG_PESSOA";
            $stmt = $this->connection->prepare( $sql );
            $stmt->bindValue( "SN_PAGO", $registro['pago'], PDO::PARAM_STR );
            $stmt->bindValue( "CD_REG_PESSOA", $registro['registro'], PDO::PARAM_INT );
            $stmt->execute();
            $this->connection->commit();
            $teste = true;
            $this->connection = null;


        }catch ( PDOException $exception ){
            Echo "Erro: ".$exception->getMessage();
        }
        return $teste;
    }

Trigger:

DELIMITER $$
  DROP TRIGGER IF EXISTS 'emiliabd'.'trg_insert_pay' $$
     CREATE TRIGGER 'emiliabd'.'trg_insert_pay' AFTER UPDATE ON registro
 FOR EACH ROW
BEGIN
        INSERT INTO pgto_pessoa VALUES (NULL, OLD.CD_REG_PESSOA, NOW(), OLD.VL_PRECO );
END $$
DELIMITER ;

And the function in javascript / jQuery

function registrarPagamento( id ){
     console.log("funcao registrarPagamento");
    $.ajax({
        url  : 'function/registro.php',
        type : 'post',
        dataType : 'json',
        beforeSend: aguardandoModal,
        data : {
            pago : 'S',
            registro : id,
            acao     : 'P'
        },
        success : function ( data ) {
            console.log("Retorno: "+data.retorno);
            if( data.retorno == 1 ){
                msgSucessoModal();
            }else{
                erroSendModal();
            }
        },
        error : function (data) {
            console.log("Erro:"+data);
        }
    })
}

Everything works, right, except that in javascript it only enters the error part. Thanks.

    
asked by anonymous 06.10.2017 / 16:24

1 answer

1

When using console.log() with a concatenated string, it is not always possible to see the actual return.

Use console.log(data); , thus passing the variable directly.

    
06.10.2017 / 16:38