Foros del Web » Programando para Internet » PHP »

update en SQL

Estas en el tema de update en SQL en el foro de PHP en Foros del Web. Ayudenme por favor!!!!. Tengo una base de datos de una muebleria, la cual tiene una tabla llamada inventario, dentro de esta el campo existencias, este ...
  #1 (permalink)  
Antiguo 05/02/2004, 14:46
 
Fecha de Ingreso: febrero-2004
Mensajes: 1
Antigüedad: 20 años, 2 meses
Puntos: 0
update en SQL

Ayudenme por favor!!!!.
Tengo una base de datos de una muebleria, la cual tiene una tabla llamada inventario, dentro de esta el campo existencias, este campo deberia de incrementarse segun la cantidad que se ingresa desde un formulario que este en html, el formulario pide datos sobre los muebles y la cantidad de muebles a ingresar, los datos se mandan a otra tabla, lo cual si lo hace, el problema es que las existencias en la tabla inventario no se incrementan.
El codigo que tenemos para tratar de realizar esto es:

libreria se nanda a llamar para conectarse.

<html>

<head>
<title>ALTAS DE ACCESORIOS</title>
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="25" link="#002266" vlink="#002266" alink="#002269" text="#FFFFFF" bgcolor="#000066">

<form action="aaccesorios.php" method=post>

<CENTER>
<BR>
<FONT SIZE=5>DAR DE ALTA ACCESORIOS</FONT><BR><BR>
<CENTER>

<table border="1" cellpadding="3" cellspacing="3" align=center>
<tr>
<th>ID:</th> <td><input type=text name="id"></td>
</tr>

<tr>
<th>CLAVE_PRODUCTO</th><td><input type=text name="cp"></td>
</tr>

<tr>
<th>CANTIDAD</th><td><input type=text name="cant"></td>
</tr>

<tr>
<th>MATERIAL</th><td><input type=text name="mat"></td>
</tr>

<tr>
<th>TIPO</th><td><input type=text name="tip"></td>
</tr>

<tr>
<th>ESTILO</th><td><input type=text name="est"></td>
</tr>

<tr>
<th>MODELO</th><td><input type=text name="mod"></td>
</tr>

<tr>
<th>DESCRIPCIÓN</th><td><input type=text name="des"></td>
</tr>

<tr>
<th>PRECIO</th><td><input type=text name="pre"></td>
</tr>

<tr>
<th>ID_PROVEEDOR</th><td><input type=text name="idp"></td>
</tr>

</table>

<BR>
<center>
<input type=submit value="Insertar registro >>">
</center>
</form>

<BR><BR><TABLE>

<?php

include("libreria.php");

$link=conectarse();

if(!empty($id))
{
// values ('$id','$cp', '$mat', '$tip','$est','$mod','$des','$pre')";from accesorios

$consulta = " select ID,CLAVE_PRODUCTO, MATERIAL, TIPO, ESTILO, MODELO, DESCRIPCIÓN, PRECIO from accesorios where id='$id'";

$result=mysql_query($consulta,$link);

while($row = mysql_fetch_array($result))
{ echo "\n <tr>";
echo "\n <td>".$row['ID']."</font ></td>";
echo "\n <td>".$row['CLAVE_PRODUCTO']."</font ></td>";
echo "\n <td>".$row['MATERIAL']."</font ></td>";
echo "\n <td>".$row['TIPO']."</font></td>";
echo "\n <td>".$row['ESTILO']."</font></td>";
echo "\n <td>".$row['MODELO']."</font></td>";
echo "\n <td>".$row['DESCRIPCIÓN']."</font></td>";
echo "\n <td>".$row['PRECIO']."</font></td>";
echo "\n </tr>";
//$i++;
}

$mera = "select EXISTENCIAS from inventario where id='$id'";
echo $mera;
$soma = mysql_query($mera,$link);
// while($row2 = mysql_fetch_array($soma))
{
echo "<tr> <td>".$row2['EXISTENCIAS']."</font ></td></tr>"; //son mayusculas
// $pi=$row2['EXISTENCIAS'];
$aux=$cant+$row2;
echo "<tr><td>HOLA1:".$aux."</td></tr>";
}
}

echo $row2;
echo "<tr><td>HOLA:".$pi."</td></tr>";

$consulta2 = " insert into inventario (ID,ID_PROVEEDOR, PRECIO) values ('$id','$idp', '$pre') ";

$cantidad3 = " insert into altas (ID, CLAVE_PRODUCTO, ID_PROVEEDOR, CANTIDAD) values ('$id', '$cp', '$idp','$cant') ";

//$consulta3="insert into accesorios (CANTIDAD) values ('$cant'+ CANTIDAD) where ID='$id'";

if( mysql_query($consulta,$link))
echo " Insercion exitosa<br>";
else
echo " Insercion NO exitosa<br>";

if( mysql_query($consulta2,$link))
echo " Insercion exitosa a inventario";
else
echo " Insercion NO exitosa a inventario";
if( mysql_query($cantidad3,$link))
echo " Insercion exitosa a ALTAS";
else
echo " Insercion NO exitosa a ALTAS";


mysql_close($link); //cierra la conexion





echo "<tr><td>".$aux."</td></tr>";

include("libreria.php");

$link=conectarse();

$nuevaexist = "update inventario set EXISTENCIAS=$aux where ID=$id";
{
//where ID=$id (EXISTENCIAS=$aux);
//$consulta2="insert into inventario (EXISTENCIAS) values ('$id','$idp', '$pre')";
}

mysql_close($link); //cierra la conexion

?>

</body>

</html>




Por favor respondan a la brevedad posible.
  #2 (permalink)  
Antiguo 05/02/2004, 15:02
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Cita:
Por favor respondan a la brevedad posible.
La petición queda hecha .. pero te recuerdo que forosdelweb.com es un lugar donde la gente pregunta y otros responden totalmente desinteresadamente .. no somos un servicio de "help desk" (aunque a veces lo parezca).

Esto no puedes hacerlo (que yo sepa):
Código PHP:
//$consulta3="insert into accesorios (CANTIDAD) values ('$cant'+ CANTIDAD) where ID='$id'"; 
Debes hacer una consulta (SELECT) por ese ID de accessorio y obtener el campo "CANTIDAD" .. sumarle tu $cant y hacer el INSERT ..

Ese tipo de operaciones que yo sepa sólo se puede hacer en UPDATES y de la forma:

campo=campo+$cantidad

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:42.