1
I need to enter data in an A table, but I have an unknown data and need to search it in table B.
Thus, I need to make a SELECT in table B and save it for later insertion in table A.
I got the result I expected, but it’s a palliative solution:
$cod = $_POST['descricao'];
$produto = $_POST['codigoproduto'];
$quant = $_POST['quantidade'];
$sqlcode = mysql_query("INSERT INTO tabelaA(codigo, codigoproduto, quantidade) SELECT codigo, 9212, codigo FROM tabelaB WHERE descricao='$cod'");
$sqlcode1 = mysql_query("UPDATE tabelaA SET codigoproduto='$produto', quantidade='$quant' WHERE codigoproduto=9212");
How to do it properly?
The problem is getting the query return?
– Bacco
Which field do you need to pick from table B? It’s the field
codigo
?– Oeslei
@I have exactly the field
codigo
– Rene Sá
how about
$sqlcode = mysql_query("INSERT INTO tabelaA(codigo, codigoproduto, quantidade) SELECT codigo, '$produto', '$quant' FROM tabelaB WHERE descricao='$cod'");
?– Caffé
@Bacco I need to know the value of the field
codigo
, in tableWHERE descricao='$cod'
then use the value ofcodigo
in tableA. I understood? :(– Rene Sá