PHP - enviar multiples registro a mysql desde php

 
Vista:
Imágen de perfil de Carlos

enviar multiples registro a mysql desde php

Publicado por Carlos (1 intervención) el 11/09/2017 20:29:50
Primero saludo a todos y agradezco el espacio...les cuento estoy monstando una plataforma para realizar pedidos a un almacen de materiales ....buscando llegue a un codigo q me envia multiples regristro q lleno a su ves con un auto complete...pero!!! al enviar se queda dando looop porun tiempo prolongado..lo logra pero por q demora tanto....ayuda q me va quedando poco tiemp opara presentar esto...y no soy muy profesional...dejo el form y el php
el form:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<form name="compra" id="compra" method="post">
  <h3 class="bg-primary text-center pad-basic no-btm">Agregar Detalle</h3>
 
  <table class="table bg-info"  id="tabla">
    <tr class="fila-base">
      <td width="10%"><input required name="idalumno[]" id="codigo" placeholder="Codigo Prod" onfocus="this.value=''; limpiar()" on/></td>
      <td width="28%"><input name="descripcion" id="descripcion" readonly disabled="disabled">
      </td>
      <td width="28%"><input required name="nombre[]" placeholder="Cantidad" id="cantidad" onKeyDown="cambiar(this)" onfocus="this.value=''"/></td>
      <td width="20%">
        <input required name="grupo[]" placeholder="Precio actual" id="precio" disabled="disabled"/>
      </td>
      <td width="23%"><input required name="carrera[]" id="precio2" placeholder="otro Precio Nuevo" onKeyDown="cambiar(this)" onfocus="this.value=''"/></td><span class="eliminar">
      <td width="2%" class="eliminar">&nbsp;</td>
      <td width="2%" class="eliminar">&nbsp;</td>
      <td width="2%" class="eliminar"><input required name="ingreso_n[]" type="hidden" value="<?php echo $row_ingreso['id_ingr']; ?>" /></td>
      <td width="2%" class="eliminar">&nbsp;</td>
      <td width="11%" class="eliminar"><input type="button"   value="Menos -"/></td></span>
      </tr>
 
  </table>
	<div class="btn-der">
 
		<button id="adicional" name="adicional" type="button" class="btn btn-warning"> Agregar item</button>
		<br /><br /><br /><br />
      <input type="submit" name="insertar" value="Enviar Ingreso" class="btn btn-info"/>
 
	</div>
</form>

y aca el php q procesa toto en la misma pagina detalle_solic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
 
	//////////////////////// PRESIONAR EL BOTÓN //////////////////////////
	if(isset($_POST['insertar']))
 
	{
 
	$items1 = ($_POST['codigo']); //codigo producto
	$items2 = ($_POST['cantidad']);   // cantidad
	$items3 = ($_POST['precio']);  //precio nuevo (sera ultimo precio en cada renovacion)
	$items4 = ($_POST['nuevoprecio']);   //recio actual para ponderar 
	$items5 = ($_POST['nro_registro']);  //Ingreso id_ingreso para controlar el detalle 
 
	///////////// SEPARAR VALORES DE ARRAYS, EN ESTE CASO SON 4 ARRAYS UNO POR CADA INPUT (ID, NOMBRE, CARRERA Y GRUPO////////////////////)
	while(true) {
 
	    //// RECUPERAR LOS VALORES DE LOS ARREGLOS ////////
	    $item1 = current($items1);
	    $item2 = current($items2);
	    $item3 = current($items3);
	    $item4 = current($items4);
		$item5 = current($items5);
 
	    ////// ASIGNARLOS A VARIABLES ///////////////////
	    $id=(( $item1 !== false) ? $item1 : ", &nbsp;");
	    $nom=(( $item2 !== false) ? $item2 : ", &nbsp;");
	    $carr=(( $item3 !== false) ? $item3 : ", &nbsp;");
	    $gru=(( $item4 !== false) ? $item4 : ", &nbsp;");
		$ing=(( $item5 !== false) ? $item5 : ", &nbsp;");
 
	    //// CONCATENAR LOS VALORES EN ORDEN PARA SU FUTURA INSERCIÓN ////////
	    $valores='('.$id.',"'.$nom.'","'.$carr.'","'.$gru.'","'.$ing.'"),';
 
	    //////// YA QUE TERMINA CON COMA CADA FILA, SE RESTA CON LA FUNCIÓN SUBSTR EN LA ULTIMA FILA /////////////////////
	    $valoresQ= substr($valores, 0, -1);
 
	    ///////// QUERY DE INSERCIÓN ////////////////////////////
	    $sql = "INSERT INTO ingreso_detall (codigo, cantidad, precio_new, precio_final,id_ingr )
		VALUES $valoresQ";
 
$insertGoTo = "listo.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
 
		$sqlRes=$conexion->query($sql) or mysql_error();
 
 
	}
 
	}
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de facundo

enviar multiples registro a mysql desde php

Publicado por facundo (185 intervenciones) el 12/09/2017 18:04:36
el loop lo hace por esto: while(true) {...}

ahi estas diciendo "mientras que sea verdadero... segui ejecutando el codigo... y siempre va a ser true porque no hiciste ninguna comparacion por ejemplo while($i < 5) {... $i++}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar