Ver Mensaje Individual
  #11 (permalink)  
Antiguo 09/06/2009, 12:22
Avatar de gjx2
gjx2
 
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: ayuda urgente

Código PHP:
<?PHP      
 
         
## Recuerda incluir tu conectar. 
 
            
if(isset($_POST["envio"])){
        
        
            for (
$a 0$a count($_POST["capacidad"]); $a++ ){
               
                    
$capacidad $_POST["capacidad"][$a];
                    
$precio_usb $_POST['precio_usb_'.$a];
                    
            
$sql_capacidad_precio  "insert into           miusb_capacidad_precio(capacidad,precio_usb)";
                    
$sql_capacidad_precio .= "values('$capacidad','$precio_usb')";
                    
                    echo 
$sql_capacidad_precio;
                    echo 
"<br/>";
                    
mysql_query($sql_capacidad_precio) or die(mysql_error());
                                    
            }  
        
        
        
        }
             
            
?>

Código Codigo formulario:
Ver original
  1. <?php
  2.  
  3.             $sql_capacidad = "SELECT * FROM miusb_capacidades";
  4.             $rpta_capacidad = mysql_query($sql_capacidad) or die(mysql_error());
  5.             $i = 0;
  6. ?>
  7.         <form name="Form" action="TuArchivophp" method="post">
  8.             <table width="197" border="0" cellspacing="0" cellpadding="0">    
  9.                 <tbody>
  10.          <?php while($capacidad = mysql_fetch_array($rpta_capacidad)):?>
  11.                
  12.          
  13.             <tr>
  14.               <td width="31"><input name="capacidad[]" type="checkbox" class="objetoformulario" id="capacidad" value="<?=$capacidad['Capacidad'];?>" /></td>
  15.               <td width="62"><?=$capacidad['Capacidad'];?></td>
  16.               <td width="104"><input name="precio_usb_<?=$i;?>" type="text" class="objetoformulario" size="12" /></td>
  17.             </tr>
  18.          
  19.            
  20.          <?php
  21.           $i++;
  22.          endwhile;    
  23.          ?>
  24.             </tbody>
  25.          </table>
  26.          <input type="submit" name="envio" value="Comprobar">
  27.          </form>

No se te olvides cambiar el Action del formulario

Intenta con este codigo.





Código La tabla miusb_capacidad_precio:
Ver original
  1. CREATE TABLE  `db`.`miusb_capacidad_precio` (
  2.   `idproducto` int(11) NOT NULL auto_increment,
  3.   `capacidad` varchar(45) NOT NULL default '',
  4.   `precio_usb` varchar(45) NOT NULL default '',
  5.   PRIMARY KEY  (`idproducto`)
  6. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;





Código La tabla miusb_capacidades:
Ver original
  1. CREATE TABLE  `sd`.`miusb_capacidades` (
  2.   `Id` int(11) NOT NULL auto_increment,
  3.   `Capacidad` varchar(45) NOT NULL default '',
  4.   PRIMARY KEY  (`Id`)
  5. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;




Código miusb_capacidades:
Ver original
  1. mysql> select * from miusb_capacidades;
  2. +----+-----------+
  3. | Id | Capacidad |
  4. +----+-----------+
  5. |  1 | 1GB       |
  6. |  2 | 2GB       |
  7. |  3 | 3GB       |
  8. |  4 | 4GB       |
  9. |  5 | 5GB       |
  10. +----+-----------+
  11. 5 rows in set (0.00 sec)
  12.  
  13. mysql>



Código miusb_capacidad_precio:
Ver original
  1. mysql> select * from miusb_capacidad_precio;
  2. +------------+-----------+------------+
  3. | idproducto | capacidad | precio_usb |
  4. +------------+-----------+------------+
  5. |         14 | 1GB       | 500        |
  6. |         15 | 2GB       | 1000       |
  7. |         16 | 3GB       | 1500       |
  8. |         17 | 4GB       | 2000       |
  9. |         18 | 5GB       | 2500       |
  10. |         19 | 1GB       | 2.3        |
  11. |         20 | 2GB       | 5.0        |
  12. |         21 | 3GB       | 3.5        |
  13. |         22 | 4GB       | 8.0        |
  14. |         23 | 5GB       | 6.4        |
  15. +------------+-----------+------------+
  16. 10 rows in set (0.00 sec)
  17.  
  18. mysql>

Última edición por gjx2; 09/06/2009 a las 12:32