Load remaining items from the array

Asked

Viewed 44 times

0

Hello,

I receive via $_POST the ID of 1 or more products, which are already saved in the 'products' table, which contains more data saved together in the table (ipi,icms) I would like to take this remaining data of each product through the ID of each product received by POST and then save through an INSERT that I already have working all down here (all that remains is to take the remaining fields from the product table of each product by its ID received in the array).

//POST em array que recebo

$valor_unitario = $_POST['valorunitario'];
$nome-produto= $_POST['nome_produto'];
$quant_produto = $_POST['quant_produto'];
$subtotal = $_POST['subtotal'];
$id_produto = $_POST['id_produto'];


//AQUI INSERE OS ARRAYS NO BANCO DE DADOS, RECEBE OS PRODUTOS ADICIONADOS VIA POST (AQUI QUERO SALVAR O RESTANTE DOS CAMPOS DO PRODUTO ATRAVÉS DO ID DELES.
$i=0;
$sql= "INSERT INTO `log_nfe_produtos` (`NOME_PRODUTO`, `VALOR_UNITARIO`, `QUANT_PRODUTO`, `SUBTOTAL`, `ID_EMPRESA`,`ID_NF`) VALUES ";

foreach($nome_produto as $p){

$sql=$sql."('$p','$valor_unitario[$i]','$quant_produto[$i]','$subtotal[$i]','1','$cod_pedido[$i]'),";

$i++;

}

$sqlFinal = substr($sql, 0, strlen($sql)-1);

$sqlFinal2 = $conn->prepare("$sqlFinal");

$sqlFinal2->execute();
  • You would have to select in the products table and get the values you want.

  • Add in your question an example of data that you receive in the POST and also how is the structure of the product table. You’ll probably have to make one INSERT SELECT instead of a INSERT VALUES and if you have the product ID do not need send to POST the product description.

  • I receive the data as ID, NAME, VALUE, I would like to receive others like ICMS, COFINS....

  • @Rafaelweber, friend, you would know how to help me implement this, ?

No answers

Browser other questions tagged

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