Ver Mensaje Individual
  #5 (permalink)  
Antiguo 11/09/2014, 07:52
Avatar de Jlopez2014
Jlopez2014
 
Fecha de Ingreso: julio-2014
Ubicación: Barranquilla
Mensajes: 154
Antigüedad: 9 años, 9 meses
Puntos: 0
Respuesta: Actualizar BD a partir de tabla php

Son distintas, mira este es el codigo completo del formulario:

Código PHP:
Ver original
  1. <?php
  2. include("conexion.php");
  3. ?>
  4. <?php include("seguridad.php");
  5. ?>
  6.  
  7. <!DOCTYPE html>
  8. <html>
  9. <head><meta http-equiv="Content-Type" content="text/html; charset=big5">
  10. <title>Cotizaci&oacute;n</title>
  11.  
  12. <LINK href="body.css" rel="stylesheet" type="text/css">
  13. </head>
  14. <body>
  15. <header>
  16. <h2><center>
  17.   <font color="navy">Editar Cotizaci&oacute;n</font>
  18. </center></h2>
  19. </header>
  20. <br>
  21. <?php
  22. $var="";
  23. $var1="";
  24. $var2="";
  25. $var3="";
  26.  
  27. $sql="select max(nopedido) from pedidos";
  28. $consult = mysql_query($sql);  
  29. $r = mysql_fetch_array($consult);
  30.  
  31.  
  32. if(isset($_POST["btn1"])){
  33.     $btn=$_POST["btn1"];
  34.     $bus=$_POST["txtbus"];
  35.     if($btn=="Buscar"){
  36.        
  37.         $sql="select * from contenidopedido where nopedido='$bus'";
  38.         $cs=mysql_query($sql,$cn);
  39.         while($resul=mysql_fetch_array($cs)){
  40.             $var=$resul[0];
  41.             $var1=$resul[1];
  42.             $var2=$resul[2];
  43.             $var3=$resul[3];
  44.             $var4=$resul[4];
  45.             $var5=$resul[5];
  46.             $var6=$resul[6];
  47.            
  48.            
  49.            
  50.             }
  51.            
  52.            
  53.         }
  54.        
  55.         if($btn=="Agregar"){
  56.        
  57.  $nopedido = $_POST['txtnopedido'];
  58.  $noproy = $_POST['txtnoproy'];
  59.  $user = $_POST['txtuser'];
  60.  $fecha = $_POST['txtfecha'];
  61. foreach($_POST['txtnopro'] as $key => $nopro)
  62. {
  63.  
  64.     $cantidad = $_POST['txtcantidad'][$key];
  65.     $obs = $_POST['txtobs'][$key];
  66.        
  67.        
  68.        
  69.         $sql="insert into contenidopedido values ($nopedido,'$nopro','$cantidad','$obs','$noproy','$user','$fecha')";
  70.        
  71.         $cs=mysql_query($sql,$cn);
  72.        
  73.        
  74. }
  75. echo "<script> alert('Se inserto correctamente el pedido');
  76. window.location='compras.php';</script>";
  77.         }
  78.        
  79.         if($btn=="Actualizar"){
  80.    
  81.     foreach($_POST['txtnoproy'] as $key => $noproyecto){
  82.         $cantidad = $_POST['txtcotiz'][$key];
  83.         $obs = $_POST['txtobscotiz'][$key];
  84.         $nopro = $_POST['txtnopro'][$key];
  85.        
  86.         $sql="update cotizaciones set idproducto='$nopro', cantidad=$cantidad, observaciones='$obs' where noproyecto='$noproyecto'";
  87.         $cs=mysql_query($sql,$cn);
  88.         }
  89.         echo "<script> alert('Se actualizo la cotizacion correctamente');
  90.         window.location='ingresoproyectos.php';</script>";
  91.         }
  92.         if($btn=="Eliminar"){
  93.         $noproyecto = $_POST["txtnoproy"];
  94.            
  95.         $sql="delete from cotizaciones where noproyecto='$noproyecto'";
  96.        
  97.         $cs=mysql_query($sql,$cn);
  98.         echo "<script> alert('Se elimnino la cotizacion correctamente');
  99.         window.location='ingresoproyectos.php';</script>";
  100.         }
  101.     }
  102.  
  103. ?>
  104. <?php
  105. $proy=$_GET['proy'];
  106. ?>
  107. <form name="fe" action="" method="post">
  108. <center>
  109. <!--<strong>No pedido:</strong>-->
  110. <?php
  111. $sql="select max(nopedido) from pedidos";
  112. $consult = mysql_query($sql);  
  113. $r = mysql_fetch_array($consult);
  114.  
  115.  
  116. ?>
  117. <input name="txtnopedido" type="hidden"  value="<?php echo $r[0]?>" size="1"/>
  118. <tr>
  119. <td width="117"><strong>Fecha: </strong><input name="txtfecha" type="text"  value=<?php echo date('m/d/Y'); ?> size="7" readonly/></td>
  120. <td width="117"><strong>Proyecto: </strong></strong><input name="txtnoproy[]" type="text"  value=<?php echo $proy?> size="10" readonly/>
  121. <td width="143"><strong>Solicitado por: </strong><input name="txtuser" type="text"  value=<? echo $_SESSION['usuarioactual']; ?> size="8" readonly/></td><br><br>
  122. <?php
  123. $sql="
  124. SELECT cotizaciones.nocotizacion, cotizaciones.idproducto, cotizaciones.cantidad, cotizaciones.observaciones
  125. FROM cotizaciones
  126. INNER JOIN pedidos
  127. WHERE cotizaciones.noproyecto = '".$proy."'
  128. GROUP BY cotizaciones.idproducto
  129. ORDER BY cotizaciones.noproyecto DESC";
  130.         $cs=mysql_query($sql,$cn);
  131.         echo"<center>
  132. <table border='4' bordercolor='#0099FF' bgcolor='#FFFFFF'>
  133. <tr>
  134. <td><font color='navy'><strong>Desc. del Producto</strong></font></td>
  135. <td><font color='navy'><strong>Cantidad<br>Cotizada</strong></font></td>
  136. <td><font color='navy'><strong>Observaciones</strong></font></td>
  137. </tr>";
  138.         while($resul=mysql_fetch_array($cs)){
  139.             $var=$resul[0];
  140.             $var1=$resul[1];
  141.             $var2=$resul[2];
  142.             $var3=$resul[3];
  143.            
  144.            
  145.             echo "<tr>
  146. <td><input name='txtnopro[]' type='text'  value='$var1' size='48'/></td>
  147. <td><input name='txtcotiz[]' type='text'  value='$var2' size='5'/>
  148. <td><textarea name='txtobscotiz[]' type='text' size='15'>$var3</textarea></td>
  149.  
  150. </tr>";
  151.             }
  152.            
  153.             echo "</table>
  154. </center>";
  155. ?>
  156. <!--
  157. <table border="4" align="center" bordercolor="#0099FF" bgcolor="#FFFFFF">
  158.  
  159. <td><strong>Productos</strong></td>
  160. <td><input name="txtnopro" type="text"  value="<?php echo $var1?>" size="6"/></td>
  161. </tr>
  162. <tr>
  163. <td><strong>Cantidad</strong></td>
  164. <td><input name="txtcantidad" type="text"  value="<?php echo $var2?>" size="6"/></td>
  165. </tr>
  166. <tr>
  167. <td><strong>Observaciones</strong></td>
  168. <td><textarea name="txtobs" cols="6" id="txtobs"><?php echo $var3?></textarea></td>
  169. </tr>
  170. <tr>
  171. -->
  172. <table width="200" border="4" align="center" bordercolor="#0099FF" bgcolor="#FFFFFF">
  173. <tr align="center"><td colspan="2"><input type="submit" name="btn1"value="Eliminar"><input type="submit" name="btn1"value="Actualizar"></td>
  174.   <tr>
  175.     <th scope="col"><a href="ingresoproyectos.php"><img src="regresar.PNG" width="68" height="26"></a></th>
  176.     <th scope="col"><a href="logout.php"><img src="sesion.PNG" width="97" height="24"></a></th>
  177.   </tr>
  178. </table>
  179. <tr>
  180. <tr><br />
  181. </form>
  182. <br />

mi tabla se llama cotizaciones y tiene los siguientes campos:

idproducto (varchar50), cantidad (int 20), observaciones (varchar 50) y noproyecto (varchar 50). txtnopro esta relacionado con idproducto y txtnoproy con el noproyecto.

no mires el boton agregar que ese es codigo viejo que no funciona y que no he limpiado pendiente de poder actualizar los datso traidos al formulario... gracias por tu tiempo :D