PHP - Is it possible to do an INSERT INTO with php variables and more SELECT?

0

I need to get information from another table and append to another table with more info from a php variable I've been researching and some forms I've found was:

INSERT INTO tabProdutos ( id, descricao, unidade, qtd, valor) VALUES (‘$id’, ‘
(SELECT cod, descricao, unidade, qtd, valor FROM tabInfoProd WHERE cod = $cod ’);

But nothing happened

What could be wrong? Thank you.

    
asked by anonymous 05.06.2017 / 14:07

1 answer

2

Your number of arguments declared in values is incorrect, try something like:

INSERT INTO tabProdutos ( id, descricao, unidade, qtd, valor) VALUES (
SELECT cod, descricao, unidade, qtd, valor FROM tabInfoProd WHERE cod = '$cod' );

or

INSERT INTO tabProdutos ( id, descricao, unidade, qtd, valor) VALUES (
SELECT '$id', descricao, unidade, qtd, valor FROM tabInfoProd WHERE cod = '$cod');
    
05.06.2017 / 14:26