Result after update

Asked

Viewed 32 times

1

Hello I would like after an execution in the database return me a value 1, 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 ) );
}

On the dao:

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 javascript/jQuery function

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, neat, only in javascript only enters the part error. Thanks

  • On entering the part error, what message the console.log returns?

  • Error:[Object Object]

  • Modifies the line to only console.log(data); and tells me what returns.

  • Interesting that it worked!

1 answer

1


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

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

  • Thanks! Thank you very much!

  • You’re welcome! I’m glad I could help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.