Foros del Web » Programando para Internet » PHP »

input insercion multiple en un for

Estas en el tema de input insercion multiple en un for en el foro de PHP en Foros del Web. hola buenas tardes o dias estoy haciendo un codigo que segun el valor tenga en un input me despliga mas input es decir si escribo ...
  #1 (permalink)  
Antiguo 23/06/2009, 12:59
 
Fecha de Ingreso: junio-2009
Mensajes: 4
Antigüedad: 14 años, 10 meses
Puntos: 0
Exclamación input insercion multiple en un for

hola buenas tardes o dias
estoy haciendo un codigo que segun el valor tenga en un input me despliga mas input es decir si escribo 5 me desplega 5 input , cada uno de los input que me despliga deven insertar un dato a mi base de datos

espero explicarme pero si no les pongo mi codigo

Código PHP:
<?php 
$txcertificacion 
= isset($_POST["txcertificacion"])? $_POST["txcertificacion"]: ''
   
//$txcertificacion=$_POST['txcertificacion'];
?>
<form id="form1" name="form1" method="post" action="for.php">
      <table width="200" border="0">
  <tr>
              <td width="108"><h3># de Modulos</h3></td>
              <td width="174"><label>
        <input type="text" name="txcertificacion" id="txcertificacion" />
      </label></td>
          <td width="66"><label>
            <input type="submit" name="button" id="button" value="Enviar" onclick="$resultado;" />
      </label></td>
    </tr>
<?php 
     
for($i=0;$i<$txcertificacion;$i++) {
?>
 
    <tr>
      <td colspan="2"><label>Nombre del modulo</label></td>
      
      <td><input name="nombre" type="text" id="nombre" value="" size="60" /></td>
        <td><?php echo"nombre$i"."   <p>&nbsp;</p>" ?></td>

 <td><?php //echo"".$n."   <p>&nbsp;</p>" ?></td>
        
        </tr>
    
 <?php 
    
}
 
?> 

  </table>
  <table width="200" border="0">
      <tr>
        <td width="108"><h3>&nbsp;</h3></td>
        <td width="174"><label></label></td>
        <td width="66"><label>
        <input type="submit" name="button2" id="button2" value="Guardar" onclick="ejemplo v1.php;" />
        </label></td>
      </tr>
      <?php 
     
for($i=0;$i<$txcertificacion;$i++) {
?>
      <?php 
    
}
 
?>
    </table>
 
</form>
  #2 (permalink)  
Antiguo 24/06/2009, 09:26
Avatar de Huacho12  
Fecha de Ingreso: septiembre-2008
Ubicación: Isla Mujeres Q. Roo
Mensajes: 175
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: input insercion multiple en un for

Hola!!!!

Wille.

Supongo que la pagina a donde mandas tu txcertificacion es la misma, entonces lo que tendrias que hacer es lo siguientes:

<?php

$txcertificacion = $_POST["txcertificacion"]; //RECIBO EL VALOR DEL TXCERTIFICACION QUE ES EL QUE VA A DECIR CUANTAS VECES QUIERO QUE SE REPITA MI IMPUT
//$txcertificacion=$_POST['txcertificacion'];

?>
<form id="form1" name="form1" method="post" action="for.php">
<table width="200" border="0">
<tr>
<td width="108"><h3># de Modulos</h3></td>
<td width="174"><label>
<input type="text" name="txcertificacion" id="txcertificacion" value="<?php echo "".$txcertificacion; //RECUPERO EL VALOR ?>" />
</label></td>
<td width="66"><label>
<input type="submit" name="button" id="button" value="Enviar" />
</label></td>
</tr>

<?php

for($i=0;$i<$txcertificacion;$i++) { //Con este for repito el numero de veces que haya puesto en el imput
?>

<tr>
<td colspan="2"><label>Nombre del modulo</label></td>

<td><input name="nombre" type="text" id="nombre" value="" size="60" /></td>

<td><?php echo "nombre $i"; ?></td>

<td><?php //echo"".$n." <p>&nbsp;</p>" ?></td>

</tr>

<?php
}
?>

</table>
<table width="200" border="0">
<tr>
<td width="108"><h3>&nbsp;</h3></td>
<td width="174"><label></label></td>
<td width="66"><label>
<input type="submit" name="button2" id="button2" value="Guardar" onclick="ejemplo_v1.php;" />
</label></td>
</tr>
</table>

</form>

Y para insetar:

$misdatos=split(",",$_POST["nombre"]);//RECUPERO LOS DATOS DEL VECTOR
$cont=count($misdatos);//CUENTO LA LONGITUD DEL VECTOR

for($i=0;$i<$cont;$i++)
{
mysql_query("insert tuTabla values (campo1,campo2,campo3,$misdatos[$i])",$tuConexion);
}

Espero te pueda servir este codigo.
Espero tus comentarios.
Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:18.