UPDATE in another table when updating a record does not work - CODEIGNITER - MYSQL

0
Hello, the code for updating a record in another table does not work.
I need to update the vendas table when saving a record of the lancamentos table.

In the lancamentos table there is the vendas_id column, which contains the id related to a billed sale. When I edit the posting, I need the idLancamentos to pass to the lancamentos_id column in the vendas table.

The controller has the following function:

            if ($this->financeiro_model->edit('lancamentos',$data,'idLancamentos',$this->input->post('id')) == TRUE) {

                //$estornado = 0;
                $venda = $this->input->post('venda_id');
                $lancamento = $this->input->post('idLancamentos');

                $sql = "UPDATE vendas set lancamentos_id = lancamentos_id = ? WHERE idVendas = ?";
                $this->db->query($sql, array($lancamento, $venda));

                $this->atualizaSaldoEditar();
                echo json_encode(array('result'=> true));

                $this->session->set_flashdata('success','lançamento editado com sucesso!');
                redirect($urlAtual);
            } else {

                $this->session->set_flashdata('error','Ocorreu um erro ao tentar editar lançamento!');
                echo json_encode(array('result'=> false));
                redirect($urlAtual);
            }

To be more precise, I believe the problem is in the Code below:

$venda = $this->input->post('venda_id');
$lancamento = $this->input->post('idLancamentos');

$sql = "UPDATE vendas set lancamentos_id = lancamentos_id = ? WHERE idVendas = ?";
$this->db->query($sql, array($lancamento, $venda));
    
asked by anonymous 04.11.2016 / 16:14

1 answer

1

Your error is in this update:

$sql = "UPDATE vendas set lancamentos_id = lancamentos_id = ? WHERE idVendas = ?";

In addition to containing syntax error using x = x = x , its lancamentos_id in querie is the column of its own table.

The correct one would simply be this here:

$sql = "UPDATE vendas set lancamentos_id = ? WHERE idVendas = ?";
    
04.11.2016 / 16:38