| |||
sumar - restar y que se guarde en el mismo campo Buenos dias foro, quisiera saber como se hace este codigo con php y mysql, tengo que hacer un inventario donde se capture entradas y salidas, y hacer la consulta gracias de antemano |
| |||
Respuesta: sumar - restar y que se guarde en el mismo campo Ok tengo un campo donde capturo con html, php <?php //Conectarse y seleccionar base de datos $link = mysql_connect('localhost', 'root',''); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('baldemar', $link); if (!$db_selected) { die ('Cant use baldemar: ' . mysql_error()); } $CC = $_POST['CC'] $que = "INSERT INTO datos (CC) "; $que.= "VALUES ('".$CC."') "; $res = mysql_query($que, $link) or die(mysql_error()); { echo "Datos insertados correctamente"; } bueno asi tomo los datos lo que quiero es que cuanto ya esten insertados me reste el resultado del campo CC y se inserte el nuevo valor si son 20 y se vuelve a campturar 15 me de un resultado de 5 en el campo CC, esto seria en una pagina y en otra pagina ya sea la resta y , gracias de nuevo por la ayuda |
| |||
Respuesta: sumar - restar y que se guarde en el mismo campo |
| |||
Respuesta: sumar - restar y que se guarde en el mismo campo Este es el codigo con el cual me captura el php con ese no tengo problema , solo quiero que en otro script me reste lo que capture con este: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> </head> <body> <p> <?php //Conectarse y seleccionar base de datos $link = mysql_connect('localhost', 'root',''); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('baldemar', $link); if (!$db_selected) { die ('Cant use baldemar: ' . mysql_error()); } $CC = $_POST['CC']; $CM= $_POST['CM']; $CG= $_POST['CG']; $CMM= $_POST['CMM']; $R15= $_POST['R15']; $R20= $_POST['R20']; $R25= $_POST['R25']; $R30= $_POST['R30']; $CCN= $_POST['CCN']; $CMN= $_POST['CMN']; $CGN= $_POST['CGN']; $CMMN= $_POST['CMMN']; $R15X= $_POST['R15X']; $R20X= $_POST['R20X']; $R25X= $_POST['R25X']; $R30X= $_POST['R30X']; $R15P= $_POST['R15P']; $R20P= $_POST['R20P']; $R25P= $_POST['R25P']; $R30P= $_POST['R30P']; $R50P= $_POST['R50P']; $R60P= $_POST['R60P']; $R15PPS= $_POST['R15PPS']; $R20PPS= $_POST['R20PPS']; $R25PPS= $_POST['R25PPS']; $R30PPS= $_POST['R30PPS']; $R50PPS= $_POST['R50PPS']; $R60PPS= $_POST['R60PPS']; $R50PB= $_POST['R50PB']; $R60PB= $_POST['R60PB']; //linea 29 $que = "INSERT INTO datos (CC, CM, CG, CMM, R15,R20 ,R25, R30, CCN, CMN, CGN, CMMN,R15X ,R20X, R25X, R30X, R15P, R20P, R25P, R30p, R50P, R60P, R15PPS,R20PPS,R25PPS, R30PPS,R50PPS,R60PPS,R50PB,R60PB ) "; $que.= "VALUES ('".$CC."', '".$CM."', '".$CG."','".$CMM."','".$R15."','".$R20."','".$R25 ."','".$R30."','".$CCN."','".$CMN."','".$CGN."' ,'".$CMMN."','".$R15X."','".$R20X."','".$R25X."',' ".$R30X."','".$R15P."','".$R20P."','".$R25P."','". $R30P."','".$R50P."','".$R60P."','".$R15PPS."','". $R20PPS."','".$R25PPS."', '".$R30PPS."','".$R50PPS."','".$R60PPS."','".$R50P B."','".$R60PB."') "; $res = mysql_query($que, $link) or die(mysql_error()); { echo "Datos insertados correctamente"; } ?> </p> </form> <p align="center"><a href="http://localhost/1/index.html">INICIO</a> <a href="http://localhost/1/consulta.php">CONSULTAS</a> <a href="http://localhost/1/1.htm">CAPTURA</a></p> </body> </html> gracias de nuevo |
| |||
Respuesta: sumar - restar y que se guarde en el mismo campo no le tomen importancia al codigo html solo es para cuando sale que los datos han sido insertados correctamente puedas regresarte al inicio o alguna otra pagina, gracias de nuevo |
| |||
Respuesta: sumar - restar y que se guarde en el mismo campo si quieres que los datos pasan a otra pagina debes guardar los datos en un arreglo con un indice $arreglo = array(); $arreglo[0] = "tu info"; $arreglo[1] = "tu info"; $arreglo[2] = "tu info"; etc.. tienes que pasarlo en un input hidden dentro de un formulario si quieres que se envien por un boton y si no dentro de un header <input type="hidden" name="mis_datos" value="<?php echo $arreglo; ?>" /> |
| ||||
Respuesta: sumar - restar y que se guarde en el mismo campo Cita: Definitivamente sólo andas hablando por hablar.
Iniciado por __SDP__ ![]() si quieres que los datos pasan a otra pagina debes guardar los datos en un arreglo con un indice $arreglo = array(); $arreglo[0] = "tu info"; $arreglo[1] = "tu info"; $arreglo[2] = "tu info"; etc.. tienes que pasarlo en un input hidden dentro de un formulario si quieres que se envien por un boton y si no dentro de un header <input type="hidden" name="mis_datos" value="<?php echo $arreglo; ?>" /> ![]() Un arreglo no se puede pasar de eso forma, porque si lo imprimes literalmente obtienes: Array Entiende que sólo puedes imprimir cadenas, si quisieras pasar la estructura completa deberías serializarla para transformar los datos en una cadena de texto, de otra forma es imposible. Además si ese fuera el problema, ¿por qué no usar sesiones? No hay necesidad de pasar nada.
__________________ Y U NO RTFM? щ(ºдºщ) No atiendo por MP nada que no sea personal. |
| |||
Respuesta: sumar - restar y que se guarde en el mismo campo Este es mi codigo html y con el codigo anterior es con el que inserto a mysql, lo que quiero es que con este mismo codigo pueda hacer otro script en php pero en lugar de insertar como lo tengo en el otro codigo me reste lo que inserte en otro script de php , de nuevo mil gracias <html> <head> <meta http-equiv="Content-Language" content="es"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>CAPTURA DE INVENTARIO RUBI</title> </head> <body text="#FF0000" bgcolor="#000000"> <p align="right"> </p> <p align="right"><font size="6">CAPTURA DE INVENTARIO RUBI</font></p> <p align="right"> </p> <p align="right"> </p> <form method="post" action="captura.php" style="text-align: right"> <p align="center"><font size="7">POLICEDA </font><font size="5"> </font></p> <p align="justify"><font size="5">CAMISETA CHICA <input type="text" name="CC" size="11"> </font></p> <p align="justify"><font size="5">CAMISETA MEDIANA <input type="text" name="CM" size="11"></font></p> <p align="justify"><font size="5">CAMISETA GRANDE <input type="text" name="CG" size="11"></font></p> <p align="justify"><font size="5">CAMISETA MINI &nbs p; <input type="text" name="CMM" size="11"></font></p> <p align="justify"><font size="5">ROLLO 15X25   ; <input type="text" name="R15" size="11"></font></p> <p align="justify"><font size="5">ROLLO 20X20 &nb sp; <input type="text" name="R20" size="11"></font></p> <p align="justify"><font size="5">ROLLO 25X35 &nb sp; <input type="text" name="R25" size="11"></font></p> <p align="justify"><font size="5">ROLLO 30X40 &nb sp; <input type="text" name="R30" size="11"></font></p> <p align="left"> </p> <p align="center"><font size="7">POLIPAPEL</font></p> <p align="justify"><font size="5">CAMISETA CHICA NEGRA &nb sp; <input type="text" name="CCN" size="11"> </font></p> <p align="justify"><font size="5">CAMISETA MEDIANA NEGRA <input type="text" name="CMN" size="11"></font></p> <p align="justify"><font size="5">CAMISETA GRANDE NEGRA <input type="text" name="CGN" size="11"></font></p> <p align="justify"><font size="5">CAMISETA MINI NEGRA   ; <input type="text" name="CMMN" size="11"></font></p> <p align="justify"><font size="5">ROLLO 15X25 &n bsp; &nbs p; <input type="text" name="R15X" size="11"></font></p> <p align="justify"><font size="5">ROLLO 20X20 &nb sp;   ; & nbsp; <input type="text" name="R20X" size="11"></font></p> <p align="justify"><font size="5">ROLLO 25X35 &nb sp;   ; & nbsp; <input type="text" name="R25X" size="11"></font></p> <p align="justify"><font size="5">ROLLO 30X40 &nb sp;   ; & nbsp; <input type="text" name="R30X" size="11"></font></p> <p align="center"><font size="7">PLÁSTICO</font><font size="5"> </font></p> <p align="justify"><font size="5">ROLLO 15X25 &n bsp; &nbs p; <input type="text" name="R15P" size="11"></font></p> <p align="justify"><font size="5">ROLLO 20X30 &nb sp;   ; & nbsp; <input type="text" name="R20P" size="11"></font></p> <p align="justify"><font size="5">ROLLO 25X35 &nb sp;   ; & nbsp; <input type="text" name="R25P" size="11"></font></p> <p align="justify"><font size="5">ROLLO 30X40 &nb sp;   ; & nbsp; <input type="text" name="R30P" size="11"></font></p> <p align="justify"><font size="5">ROLLO 50X70 &nb sp;   ; & nbsp; <input type="text" name="R50P" size="11"></font></p> <p align="justify"><font size="5">ROLLO 60X90 &nb sp;   ; & nbsp; <input type="text" name="R60P" size="11"></font></p> <p align="center"><font size="7">PLÁSTICO - PAQUETE SUELTO</font></p> <p align="justify"><font size="5">ROLLO 15X25 &n bsp; &nbs p; <input type="text" name="R15PPS" size="11"></font></p> <p align="justify"><font size="5">ROLLO 20X30 &nb sp;   ; & nbsp; <input type="text" name="R20PPS" size="11"></font></p> <p align="justify"><font size="5">ROLLO 25X35 &nb sp;   ; & nbsp; <input type="text" name="R25PPS" size="11"></font></p> <p align="justify"><font size="5">ROLLO 30X40 &nb sp;   ; & nbsp; <input type="text" name="R30PPS" size="11"></font></p> <p align="justify"><font size="5">ROLLO 50X70 &nb sp;   ; & nbsp; <input type="text" name="R50PPS" size="11"></font></p> <p align="justify"><font size="5">ROLLO 60X90 &nb sp;   ; & nbsp; <input type="text" name="R60PPS" size="11"></font></p> <p align="center"><font size="7">PLÁSTICO - BASURA</font></p> <p align="justify"><font size="5">ROLLO 60X90 &nb sp;   ; &n bsp; <input type="text" name="R50PB" size="11"></font></p> <p align="justify"><font size="5">ROLLO 90X120 &n bsp; &nbs p; <input type="text" name="R60PB" size="11"></font></p> <p align="center"> </p> <p align="center"> </p> <p align="center"><font size="5"> <input type="submit" value="GUARDAR" name="B1"></font></p> </form> <p align="right"><a href="index.htm">INICIO</a> <a href="http://localhost/1/2.htm">CONSULTAS</a> <a href="captura.htm">CAPTURA</a> <a href="SALIDA.htm"> SALIDA</a></p> </body> </html> |
| ||||
Respuesta: sumar - restar y que se guarde en el mismo campo Si lo quieres hacer "automaticamente" tendrás que programar un trigger en la base de datos. Si lo quieres hacer con PHP, entonces con la funcion mysql_insert_id() sabrás que id tiene el último registro insertado, lo seleccionas, haces las operaciones que quieres y luego haces un UPDATE.
__________________ Fere libenter homines, id quod volunt, credunt. |
Etiquetas: |