Ver Mensaje Individual
  #3 (permalink)  
Antiguo 21/01/2015, 23:53
mbrisenog
 
Fecha de Ingreso: diciembre-2014
Mensajes: 72
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: guardar valores de input text en arreglos

Este es mi formulario en un archivo generar.php

Código HTML:
Ver original
  1. <form method="post" action="cotizador.php">
  2. <input type="text" name="cantidad">
  3. <input type="text" name="descripcion">
  4. <input type="text" name="precio">
  5. <input type="submit" value="agregar fila">
  6. </form>

Despues recibo los datos en cotizador.php y los guardo en mysql
Código PHP:
Ver original
  1. $cantidad=$_POST["cantidad"];
  2. $descripcion=$_POST["descripcion"];
  3. $precio=$_POST["precio"];
  4.  
  5. $sql = 'INSERT INTO temporal (cantidad, descripcion, precio) VALUES (\''.$cantidad.'\',\''.$descripcion.'\',\''.$precio.'\')';
  6.  
  7.  
  8. $tempo = mysql_query("SELECT * FROM temporal ");

y aqui me imprime los valores que tengo almacenados
Código HTML:
Ver original
  1.                 <tr><td>CANTIDAD</td><td>DESCRIPCION</td><td>PRECIO</td></tr>
  2.                 <? while($row=mysql_fetch_array($tempo)){ ?>
  3.                 <tr>
  4.                 <td><input type="text" name="arraycantidad[]" value=<? echo $row[1]; ?> ></td>
  5.                 <td><input type="text" name="arraydescripcion[]"  value=<? echo $row[2]; ?> ></td>
  6.                 <td><input type="text" name="arrayprecio[]"  value=<? echo $row[3]; ?> /></td>
  7.                
  8.                 </tr>
  9.                 <? }
  10.  
  11.                ?>
Y vuelvo a tener mi formulario inicial para que se vayan agregando filas

Código PHP:
Ver original
  1. <form method="post" action="cotizador.php">
  2. <input type="text" name="cantidad">
  3. <input type="text" name="descripcion">
  4. <input type="text" name="precio">
  5. <input type="submit" value="agregar fila">
  6. </form>

Y aqui lo imprimo unicamente para prueba y saber q se esta guardando pero no se guarda

Código PHP:
Ver original
  1. if(empty($arraycantidad))
  2. {echo"<p>Vacio</p>";}
  3. else
  4. {
  5. foreach ($arraycantidad as $val)
  6.   {
  7.     echo $val;
  8.   }
  9. }