
Actualizar datos de una venta
Publicado por felipe (5 intervenciones) el 14/02/2022 02:17:35
Hola comunidad, les comento que por cosas de un negocio estoy realizando un sistema de control de ventas y de inventario con PHP Y MYSQL, este esta funcionando correctamente pero en una mejora que le he hecho estoy peliando hace dias con un codigo que lo que tiene que hacer es permitir modificar y/o actualizar las ventas que se han realizado a un cliente x en un dia.
La venta diaria la muestro en form con este select.
y muestro los datos en el form con un do while, esto funciona correcto
El probleba es que cuando envio el formulario a modifica.php que es la misma pagina, me actualiza el ultimo dato listado en el form, se deberia poder actualizar la cantidad y el total de cualquier podructo que este en formulario, pero solo me actualiza el ultimo o todos.
El codigo que estoy ocupando para hacer el update el es siguiente:
hago el update pero actualiza el ultimo registros aunque meto los datos en arrays para tenerlos todos..
Apelo a su tiempo y buena dispocision si me pueden orientar gracias.
La venta diaria la muestro en form con este select.
1
$query_actualiza = "SELECT ventas.id as idventa, ventas.PRODUCTO AS PROD,ventas.CANTIDAD AS CANTIDAD,ventas.VALOR AS VALOR, ventas.TOTAL AS TOT_VENT,ventas.ID_PRODUCTO AS IDPRODUCTO FROM ventas,pedidosrealizados WHERE ventas.ID_CLIENTE = $id_cliente AND ventas.FECHA_PEDIDO = CURDATE() AND ventas.ID_CLIENTE = pedidosrealizados.ID_CLIENTE AND pedidosrealizados.ID_VENTAS=$idventa"
y muestro los datos en el form con un do while, esto funciona correcto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<h1>Modifica venta</h1>
<p> </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="95%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="tablaprincipal">PRODUCTO</td>
<td align="center" class="tablaprincipal"> CANTIDAD</td>
<td align="center" class="tablaprincipal">VALOR</td>
<td align="center" class="tablaprincipal">TOTAL</td>
</tr>
<?php
$id_producto=0;
$cont=0;
do {
?>
<form action="modifica.php" method="POST" name="form1" id="form1">
<tr>
<td><input name="PRODUCTO[]" type="text" id="prod" value="<?php echo $row_actualiza['PROD']; ?>" readonly="readonly" /></td>
<td><input name="CANTIDAD[]" type="text" id="cant" value="<?php echo $row_actualiza['CANTIDAD']; ?>"/></td>
<td><input name="VALOR[]" type="text" id="val" value="<?php echo $row_actualiza['VALOR']; ?>" /></td>
<td><input name="TOTAL[]" type="text" id="tot" value="<?php echo $row_actualiza['TOT_VENT']; ?>" readonly="readonly" /></td>
</tr>
<p>
<input type="hidden" name="ID_PRODUCTO[]" id="idproducto" value="<?php echo$row_actualiza["IDPRODUCTO"]; ?>" />
<input type="hidden" name="ID" id="ID" value=" <?php echo$row_actualiza["idventa"]; ?>" />
<input type="hidden" name="ID2[]" id="ID2" value=" <?php echo$row_actualiza["idventa"]; ?>" />
<?php
} while ($row_actualiza = mysqli_fetch_assoc($actualiza));
?>
</p>
<tr>
<td class="boton" align="center"><input type="submit" value="Modificar Venta" /></td>
<input type="hidden" name="id_cliente" value="<?php echo $id_cliente;?>" />
<input type="hidden" name="FECHA_PEDIDO" value="<?php echo $hoy; ?>" />
<input type="hidden" name="MM_update" value="form1" />
El codigo que estoy ocupando para hacer el update el es siguiente:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1"))
{
foreach ($_POST['ID2'] as $IDVENTA){
$IDVENTA."<br>";
foreach ($_POST["PRODUCTO"] as $PROD ){
$PROD."<br>";
}
foreach ($_POST["CANTIDAD"] as $CANT){
$CANT;
}
foreach ($_POST["VALOR"] as $VALOR){
$VALOR."<br>";
}
foreach ($_POST["TOTAL"] as $TOTAL){
$TOTAL."<br>";
}
foreach ($_POST["ID_PRODUCTO"] as $ID){
$ID."<br>";
$TOTALF= $CANT*$VALOR;
$updateSQL = "UPDATE ventas SET PRODUCTO='$PROD',CANTIDAD='$CANT',VALOR='$VALOR',TOTAL='$TOTALF' WHERE ID='$IDVENTA' and ID_PRODUCTO='$ID' and ID_CLIENTE='$_POST[id_cliente]'and FECHA_PEDIDO='$_POST[FECHA_PEDIDO]'";
$Result1 = mysqli_query($conexion, $updateSQL) or die(mysql_error());
if($result) }
{
//OK
echo"
<script language='javascript'>
alert('Producto actualizado exitosamente')
</script>";
}
Apelo a su tiempo y buena dispocision si me pueden orientar gracias.
Valora esta pregunta


0