Error 'Duplicate entry' 1 'for key' PRIMARY '"

2

I'm not sure how to do this, but I'm not sure how to do this.

Duplicate entry '1' for key 'PRIMARY'

Using the following code:

    mysql_query("INSERT INTO vendaproduto (id, id_venda, produtos)
SELECT venda.id_venda, venda.id_venda, venda.produtos
FROM venda")or die(mysql_error());

mysql_query("INSERT INTO vendaservico (id, id_venda, servicos)
SELECT venda.id_venda, venda.id_venda, venda.servicos
FROM venda")or die(mysql_error()); 

So I tried like this:

mysql_query("INSERT INTO vendaproduto (id_venda, produtos)
      SELECT venda.id_venda, venda.produtos
      FROM venda")or die(mysql_error());

mysql_query("INSERT INTO vendaservico (id_venda, servicos)
      SELECT venda.id_venda, venda.servicos
      FROM venda")or die(mysql_error());

So, every time I enter the data in the table it duplicates the data, someone knows where I'm going wrong or can give me some help, obg.

Full Code:     

if(isset($_POST['send'])){
    $venda = $_POST['num_venda'];
    $data = $_POST['data_venda'];
    $placa = $_POST['placa'];
    $km = $_POST['km'];
    $produtos = $_POST['produtos'];
    $servicos = $_POST['servicos'];


    include ('banco.php');


    mysql_query("INSERT INTO venda(id_venda, num_venda, data_venda, placa, km, produtos, servicos)
            values(
                NULL,
                '{$venda}',
                '{$data}',
                '{$placa}',
                '{$km}',
                '{$produtos}',
                '{$servicos}'

                            )
            ");


    header("location:lista.php");

}


mysql_query("INSERT INTO vendaproduto (id, id_venda, produtos)
          SELECT venda.id_venda, venda.id_venda, venda.produtos
          FROM venda");

mysql_query("INSERT INTO vendaservico (id, id_venda, servicos)
          SELECT venda.id_venda, venda.id_venda, venda.servicos
          FROM venda") ;

?>
    
asked by anonymous 14.12.2015 / 13:59

1 answer

2

If the primary key column has auto increment, you do not have to put it in INSERT . Clear your table and run the tests again.

Comment on INSERT and rotate the page. Then it comments the other INSERT and rotates the page. See if it doubles.

Oh, and post PHP of your code as well. Sometimes you can have something before you're causing it, like a while or for .

    
14.12.2015 / 14:17