update array
Posted: Sun Aug 24, 2014 11:03 pm
hi
I am developing a simple shopping cart.
I add the products into your cart and is correctly showing the products and adding the quatidade accordingly.
My problem is the following:
my client requests that unless the amount of product q left the store stock and the value that was sold.
eg
product1 sold the two amounts by $ 30.00 for a total of $ 60.00 for 2 and product2 20.00 giving a total of $ 40.00
following this example, do the update in the inventory table properly and this saving amount, giving low properly.
however the value sold saving this wrong, this saving the value of the last product added to the cart, then the two products save the value of $ 40.00.
could help me with this problem?
code;
My problem was this line
Thanks
I am developing a simple shopping cart.
I add the products into your cart and is correctly showing the products and adding the quatidade accordingly.
My problem is the following:
my client requests that unless the amount of product q left the store stock and the value that was sold.
eg
product1 sold the two amounts by $ 30.00 for a total of $ 60.00 for 2 and product2 20.00 giving a total of $ 40.00
following this example, do the update in the inventory table properly and this saving amount, giving low properly.
however the value sold saving this wrong, this saving the value of the last product added to the cart, then the two products save the value of $ 40.00.
could help me with this problem?
code;
Code: Select all
<form action="?acao=up" method="post">
<tfoot>
<tr>
<td colspan="5"><input type="submit" value="Atualizar Carrinho" /></td>
<tr>
<td colspan="5"><a href="vender.php">Continuar Comprando</a></td>
</tfoot>
<tbody>
<?php
if(count($_SESSION['carrinho']) == 0){
echo '<tr><td colspan="5">Não há produto no carrinho</td></tr>';
}else{
require("conexao.php");
$total = 0;
foreach($_SESSION['carrinho'] as $idproduto => $qtd){
$sql = "SELECT * FROM estoque WHERE idproduto= '$idproduto'";
$qr = mysql_query($sql) or die(mysql_error());
$ln = mysql_fetch_assoc($qr);
$idprodut = $ln['idproduto'];
$marca = $ln['marca'];
$modelo = $ln['modelo'];
$cor = $ln['cor'];
$numero = $ln['numero'];
$preco = number_format($ln['precovenda'], 2, ',', '.');
$sub = number_format($ln['precovenda'] * $qtd, 2, ',', '.');
$total += $ln['precovenda'] * $qtd;
echo '<tr>
<td>'.$idprodut.'</td>
<td>'.$marca.'</td>
<td>'.$modelo.'</td>
<td>'.$cor.'</td>
<td>'.$numero.'</td>
<td><input type="text" size="3" name="prod['.$idproduto.']" value="'.$qtd.'" /></td>
<td>R$ '.$preco.'</td>
<td>R$ '.$sub.'</td>
<td><a href="?acao=del&id='.$idproduto.'">Remove</a></td>
</tr>';
}
$total = number_format($total, 2, ',', '.');
echo '<tr>
<td colspan="4">Total</td>
<td>R$ '.$total.'</td>
</tr>';
}
?>
</tbody>
</form>
</table>
<?php
if(isset($_POST['enviar'])){
$sqlinserevenda = mysql_query("INSERT into pedido(valortotal,data) VALUES ('$total',NOW())");
$idvenda = mysql_insert_id();
foreach($_SESSION['carrinho'] as $idproduto => $qtd){
$sub = $ln['precovenda'] * $qtd;
$sqlinsereitens = mysql_query("INSERT into itenspedido(idpedido,idproduto,quantidade) VALUES('$idvenda','$idproduto','$qtd')");
$sqlestoque = mysql_query("UPDATE estoque SET quantidade = quantidade - '$qtd' WHERE idproduto = '$idproduto' ") or die(mysql_error());
$sqlestoque1 = mysql_query("UPDATE estoque SET totalvenda = totalvenda + '$sub' WHERE idproduto = '$idproduto' ") or die(mysql_error());
}
echo '<script> alert("Venda concluida!")</script>';
}
?>
Code: Select all
$sqlestoque1 = mysql_query("UPDATE estoque SET totalvenda = totalvenda + '$sub' WHERE idproduto = '$idproduto' ") or die(mysql_error());