Return different from desired in function

Asked

Viewed 30 times

0

The id is not returning after insertion, what may be wrong? I did the test with the printf but nothing appears

public function cadastrar($pdo){
        $sql = $pdo->prepare("INSERT INTO servicos(Cod_pet_servico,Pet_nome,Proprietario_cliente,Tipo_servico,Pacote_servico,Encaixe_servico,Data_servico,Hora_chegada_servico,Hora_servico,Delivery_servico,Maquina_lamina_servico,Observacoes_servico,Pagamento_servico,Apagar_servico,Total_desconto_servico,Desconto_servico,Total_servico) VALUES(:cdp,:pn,:pc,:ts,:ps,:ens,:ds,:hcs,:hs,:dls,:mls,:obs,:pgs,:ags,:tds,:dcs,:tls)");
        $sql->BindValue(':cdp',$this->cod_pet_servico);
        $sql->BindValue(':pn',$this->pet_nome);
        $sql->BindValue(':pc',$this->proprietario_cliente);
        $sql->BindValue(':ts',$this->tipo_servico);
        $sql->BindValue(':ps',$this->pacote_servico);
        $sql->BindValue(':ens',$this->encaixe_servico);
        $sql->BindValue(':ds',$this->data_servico);
        $sql->BindValue(':hcs',$this->hora_chegada_servico);
        $sql->BindValue(':hs',$this->hora_servico);
        $sql->BindValue(':dls',$this->delivery_servico);
        $sql->BindValue(':mls',$this->maquina_lamina_servico);
        $sql->BindValue(':obs',$this->observacoes_servico);
        $sql->BindValue(':pgs',$this->pagamento_servico);
        $sql->BindValue(':ags',$this->apagar_servico);
        $sql->BindValue(':tds',$this->total_desconto_servico);
        $sql->BindValue(':dcs',$this->desconto_servico);
        $sql->BindValue(':tls',$this->total_servico);
        return $sql->execute();
        $LAST_ID = $pdo->lastInsertId();
        printf($LAST_ID);
    }

1 answer

1


On the line return $sql->execute(); you return the query execution and therefore nothing runs after that. Remove the keyword return and add it at the end of the function followed by the variable with id (return $LAST_ID;)

Browser other questions tagged

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