Ver Mensaje Individual
  #8 (permalink)  
Antiguo 30/11/2010, 09:34
flor_2711
 
Fecha de Ingreso: noviembre-2010
Ubicación: The Sky
Mensajes: 11
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Bucle para insertar varios registros en un BD

Nano__ muchas gracias ya solucionamos el problema:

El Formulario:
Código PHP:
<?php   
    $linea 
= 1;   
                        
    while(
$row = mysql_fetch_array($res2,  MYSQL_ASSOC)) {
          
$Cod_A = $row{'Cod_A'};
        
$Nombre_A = $row{'Nombre_A'};
        
$cantidad = $row{'cantidad'};
        
        echo(
"<tr><td><input type='checkbox' name='Codigo[]' value='$Cod_A'>"."<td>".$Cod_A."</td> <td>".$Nombre_A."</td> <td>".$cantidad."</td>");
        echo 
"<input type='hidden' name='Cod_A$linea' value='".$Cod_A."'>"; 
        echo 
"<input type='hidden' name='cantidad$linea' value='".$cantidad."'>";                            
        echo 
"<input type='hidden' name='linea' value='".$linea."'>";
        
$linea++;
    }     
    
mysql_free_result($res);
                    
    echo 
"</form>";
?>
El script PHP:
Código PHP:
$Codigo_RS= $_POST['Cod_RS'];
$linea = $_POST['linea']; echo $linea;
for (
$i=1; $i<=$linea; $i++) {
        
$cant = substr_replace('cantidad', $i, 8);
        
$cantidad = $_POST[$cant];
        
    
$C_A = substr_replace('Cod_A', $i, 5);
        
$Cod_A = $_POST[$C_A];
                
        
$sql2="INSERT INTO detalle_reg_s (Insumo_Det, Cod_RS, Cantidad) VALUES ('$Cod_A', $Codigo_RS, $cantidad)";
        
$res2=mysql_query($sql2, $dbd);
        echo 
mysql_error();
        
}