1
I have a question. I need to subtract a row (quantity) from the table (sales) that was entered by the user on form, in the table(products) in the row(stock), and only the last record registered in the table(products) has to be made. I made a form of registration of the sale, where he inserts the data in the table for registration, and then created a update to update the stock value(stock-quantity=stock). My PHP code I am using was this:
    <?php 
include 'conexao.php';
$id = $_POST['id'] // Este id só existe na tabela de vendas, na tabela de produto é id_produtos
$cd_barras = $_POST["cd_barras"] // 
$nomeproduto =$_POST["nomeproduto"]
$preco_venda = $_POST["preco_venda"]
$quantidade = $_POST["quantidade"]
$tamanho = $_POST["tamanho"]
$decqtde = $quantidade ; // variável para subtração estoque-quantidade
$sql = "INSERT into vendaprodutos (cd_barras, nomeproduto, preco_venda, quantidade, tamanho) VALUES (NULL,'$cd_barras','$nomeproduto','$preco_venda','$quantidade','$tamanho')";
mysql_query($sql,);
$sql = "UPDATE produtos set produtos.estoque = vendaproduto.quantidade WHERE id = '$cd_barras'; "; 
mysql_query($sql); 
header("Location: venda.php");
?>
They can help me because I searched some forums and could not solve.
Have you tried using mysql_insert_id()? it looks for the last inserted ID, so that you subtract that product, in the quantity... And you need to set different variables to Insert and update... In my opinion.
– Sr. André Baill