Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/06/2004, 12:11
xcopy
 
Fecha de Ingreso: noviembre-2003
Mensajes: 38
Antigüedad: 20 años, 6 meses
Puntos: 0
Sumando datos de MYSQL

Hola a todos, tengo un problema que me esta volviendo loco , se trata de esto, tengo una cantidad X en un base de datos, bien, por medio de un formulario me gustaria sumarle algo a esa cantidad en la base de datos, intente varias cosas, inclusive la mas reciente esta medio loca, aqui les pongo mi codigo, espero puedan ayudarme.

<?

include ("conexion.php");


$base = "SELECT * FROM ingredientes ORDER BY id";
$sqla = mysql_query ($base);
?>


<form method="POST" action=<? $PHP_SELF ?>><table border="1" cellspacing="1" width="43%">
<tr>
<td width="40%">Producto</td>
<td width="29%">Cantidad</td>
<td width="31%">Ajuste de cantidad</td>
</tr>
<? while ($row = mysql_fetch_array ($sqla,MYSQL_ASSOC)){
$id = $row ["id"];
$ingrediente=$row["ingrediente"];
$cantidad=$row["cantidad"]; ?>
<tr>
<td width="40%" nowrap><? echo "$ingrediente"; ?></td>
<td width="29%" nowrap><? echo "$cantidad" ?></td>
<td width="31%" nowrap><input type="text" name="cantidadnueva" size="20"></td>
</tr><p> <? } ?>
</table>
<p><input type="submit" value="Enviar" name="submit"></p>
</form>

<?
if ($submit) {

$sql2 = "INSERT INTO ingredientes (cantidadnueva) VALUES ('$cantidadnueva')";
mysql_query ($sql2);

$cantidad1 = "SELECT cantidad, cantidadnueva, (cantidad+cantidadnueva) FROM ingredientes";
mysql_query ($cantidad1);

$sql = "INSERT INTO ingredientes (cantidad) VALUES ('$cantidad1') WHERE ingrediente = 'ingrediente'";
mysql_query($sql);

echo "Cantidades agregadas con exito";

}