Ver Mensaje Individual
  #31 (permalink)  
Antiguo 15/01/2011, 13:48
dasa
 
Fecha de Ingreso: marzo-2009
Mensajes: 132
Antigüedad: 15 años, 1 mes
Puntos: 8
Respuesta: Insertar multiples Registros

Gracias, por responder, pero mira que tengo en cod_ips es el campo que se llama inst, alli almaceno un numero.

Arregle el formulario, pero me esta guardando solo la fecha y la Institución, lo demás no lo guarda, anexo el codigo para que me puedas hacer el favor de revisarlo, ya que necesito X(5,10,15 registros) datos en pedidos

Código PHP:
Ver original
  1. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  2.  
  3. foreach($_POST['cod_ips'] as $key => $val){
  4.  
  5.   $insertSQL = sprintf("INSERT INTO pedidos (cod_ips, fecha_solicitud, suministro, presentacion, casa_productora, cantidad) VALUES (%s, %s, %s, %s, %s, %s)",
  6.                        GetSQLValueString($_POST['inst'][$key], "int"),
  7.                        GetSQLValueString($_POST['fecha_solicitud'][$key], "text"),
  8.                        GetSQLValueString($_POST['suministro'][$key], "text"),
  9.                        GetSQLValueString($_POST['presentacion'][$key], "text"),
  10.                        GetSQLValueString($_POST['casa'][$key], "text"),
  11.                        GetSQLValueString($_POST['cantidad'][$key], "text"));
  12.  
  13.   mysql_select_db($TU_BASEDEDATOS, $TU_CONEXION);
  14.   $Result1 = mysql_query($insertSQL, $TU_CONEXION) or die(mysql_error());
  15.  }
  16. }
  17. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  18. <html xmlns="http://www.w3.org/1999/xhtml">
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <title>****</title>
  22. <script>
  23. function agregaFila( id ) {
  24. var tabla = document.getElementById( id );
  25. var tbody = document.getElementById( tabla.id ).tBodies[0];
  26. var row = tbody.rows[0] .cloneNode( true );
  27. var id = 1;
  28. while( document.getElementById( tabla.id+'_fila_'+id ) ) {
  29. id++;
  30.  
  31. }
  32. if (id<=21){
  33. row.id = tabla.id+'_fila_'+id;
  34. row.style.display = '';
  35. tbody.appendChild( row );
  36. }
  37. }
  38.  
  39. function borraFila( fila ) {
  40. var id = fila.id;
  41. if( fila.parentNode.rows.length <= 2 ) return;
  42. document.getElementById( id ).parentNode.removeChild( document.getElementById(id) );
  43. }
  44.  
  45. </script>
  46.  
  47. <style type="text/css">
  48. <!--
  49. .Estilo1 {  font-size: 80%;
  50.     color: #006699;
  51.     font-weight: bold;
  52. }
  53. .Estilo2 {color: #000000}
  54. .Estilo6 {color: #0066FF}
  55. -->
  56. </style>
  57. </head>
  58.  
  59. <body class="twoColFixLtHdr">
  60. <p>&nbsp;</p>
  61.         <p>&nbsp;</p>
  62. <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  63.           <table width="223" border="0" align="center">
  64.             <tr>
  65.               <td width="152"><fieldset>
  66.                 <legend class="Estilo1 Estilo2">Fecha</legend>
  67.               <label>
  68.               <input name="fecha_solicitud[]" type="text" id="fecha_solicitud" size="12"/>
  69.               </label>
  70.               <input name="fecha_solicitud[]" type="hidden" id="fecha_solicitud" value="<?php echo $fecha_solicitud?>" />
  71.               </fieldset>              </td>
  72.               <td width="32">&nbsp;</td>
  73.               <td width="8">&nbsp;</td>
  74.               <td width="13">&nbsp;</td>
  75.             </tr>
  76.           </table>
  77.           <table width="612" border="0">
  78.             <tr>
  79.               <td width="154"><fieldset>
  80.                 <legend class="Estilo1 Estilo2">Departamento</legend> - //[B]no son necesarios[/B]
  81.                 <label>
  82.                 <input name="departamento" type="text" id="departamento" size="15" /> - //[B]no son necesarios[/B]
  83.                 </label>
  84.               </fieldset></td>
  85.               <td width="10">&nbsp;</td>
  86.               <td width="15">&nbsp;</td>
  87.               <td width="156"><fieldset>
  88.                 <legend class="Estilo1 Estilo2">Ciudad</legend> - //[B]no son necesarios[/B]
  89.                 <label>
  90.                 <input name="ciudad" type="text" id="ciudad" size="15" /> -  //[B]no son necesarios[/B]
  91.                 </label>
  92.               </fieldset></td>
  93.               <td width="8">&nbsp;</td>
  94.               <td width="15">&nbsp;</td>
  95.               <td width="212"><fieldset>
  96.                 <legend class="Estilo1 Estilo2">Institución</legend>
  97.                 <label>
  98.                 <input type="text" name="inst[]" id="inst" />
  99.                 </label>
  100.                 <input name="cod_ips[]" type="hidden" id="cod_ips" value="<?php echo $inst?>" />
  101.               </fieldset></td>
  102.               <td width="15">&nbsp;</td>
  103.             </tr>
  104.           </table>
  105.           <p>&nbsp;</p>
  106.           <table id="tabla_1" align="center">
  107.             <thead>
  108.               <tr valign="baseline">
  109.                 <td align="center" class="Estilo1 Estilo2">Biologico</td>
  110.                 <td align="center" class="Estilo1 Estilo2">Presentación</td>
  111.                 <td align="center" class="Estilo1 Estilo2">Casa Productora</td>
  112.                 <td align="center" class="Estilo1 Estilo2">Cantidad</td>
  113.                 <td></td>
  114.               </tr>
  115.             </thead>
  116.             <tbody>
  117.               <tr id="clonable" style="display:none">
  118.                 <td><label>
  119.                 <select name="suministro[]" id="suministro" value="">
  120.                   <option>Seleccionar</option>
  121.                   <option value="1">1</option>
  122.                   <option value="2">2</option>
  123.                   <option value="3">3</option>
  124.                   <option value="4">4</option>
  125.                   <option value="5">5</option>
  126.                   <option value="6">6</option>
  127.                   <option value="7">7</option>
  128.                   <option value="8">8</option>
  129.                   <option value="9">9</option>
  130.                   <option value="10">10</option>
  131.                   <option value="11">11</option>
  132.                   <option value="12">12</option>
  133.                   <option value="13">13</option>
  134.                   <option value="14">14</option>
  135.                 </select>
  136.                 <input name="suministro[]" type="hidden" id="suministro" value="<?php echo $suministro?>" />
  137.                 </label></td>
  138.                 <td><input name="presentacion[]" type="text" id="presentacion" size="20" />
  139.                 <input name="presentacion[]" type="hidden" id="presentacion" value="<?php echo $presentacion?>" /></td>
  140.                 <td><input name="casa[]" type="text" id="casa" size="15" />
  141.                 <input name="casa_productora[]" type="hidden" id="casa_productora" value="<?php echo $casa?>" /></td>
  142.                 <td><input name="cantidad1[]" type="text" id="cantidad1[]" value="" size="10" />
  143.                 <input name="cantidad[]" type="hidden" id="cantidad" value="<?php echo $cantidad1?>" /></td>
  144.                 <td><a href="#" class="Estilo6" onclick="borraFila(this.parentNode.parentNode)">Eliminar</a></td>
  145.               </tr>
  146.             </tbody>
  147.             <tr valign="baseline">
  148.               <td nowrap="nowrap" align="center"><a href="javascript:agregaFila( 'tabla_1' );" class="Estilo6">Añadir</a></td>
  149.               <td colspan="4" align="center"><input type="submit" value="Insertar registro" /></td>
  150.             </tr>
  151.           </table>
  152.   <p>&nbsp;</p>
  153.   <input type="hidden" name="MM_insert" value="form1" />
  154. </form>
  155.  </body>
  156. </html>

Te agradesco mucho.