Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/08/2014, 14:26
Avatar de Triby
Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Insertar datos con un WHILE PHP

No se trata de que todos los input tengan el mismo nombre, solo hacerlos funcionar como array:

Código HTML:
Ver original
  1. <td><input name='txtnopro[]' type='text'  value='$var1' size='15' readonly/></td>
  2. <td><input name='txtcotiz[]' type='text'  value='$var2' size='15' readonly/></td>
  3. <td><input name='txtcantidad[]' type='text'  value='' size='15'/></td>
  4. <td><input name='txtobs[]' type='text'  value='' size='15'/></td>

Luego, al procesar el formulario, todos los campos tendrán la misma cantidad de elementos, por lo que el índice de uno te servirá para los demás:

Código PHP:
Ver original
  1. foreach($_POST['txtnopro'] as $key => $txtnopro) {
  2.     // Ya tienes la variable $txtnopro, no necesitas crearla
  3.     $txtcotiz = $_POST['txtcotiz'][$key];
  4.     $txtcantidad = $_POST['txtcantidad'][$key];
  5.     $txtobs = $_POST['txtobs'][$key];
  6.  
  7.     // Aquí ejecutas la consulta para insertar y listo.
  8. }
__________________
- León, Guanajuato
- GV-Foto