este codigo uso para crear el formulario y capturo los valores:
Código PHP:
Ver original
<?php foreach ($_POST['municipio'] as $value){ foreach($value as $llave=>$valor){ $arr[$llave] = $valor; } } echo "<pre>"; echo "</pre>"; } ?> <?php echo $row; foreach ($_POST['municipio2'] as $value2){ foreach($value2 as $llave2=>$valor2){ $arr2[$llave2] = $valor2; } } echo "<pre>"; echo "</pre>"; } ?> <?php foreach ($_POST['municipio3'] as $value3){ foreach($value3 as $llave3=>$valor3){ $arr3[$llave3] = $valor3; } } echo "<pre>"; echo "</pre>"; } ?> <form action="" method="post"> <table width="485" border="1"> <tr> <th width="87" scope="row"><div align="left">CODIGO</div></th> <td width="87">DEPT1</td> <td width="147">DEPTO2</td> <td width="136">DEPTO3</td> </tr> </table> <p><?php include('conexion.php'); $sql = "SELECT * FROM empresas"; $cont++; echo $row1['cod_empresa']; ?> <input type="text" name="municipio[][<?php echo $municipio; ?>]"/> <input type="text" name="municipio2[][<?php echo $municipio2; ?>]"/> <input type="text" name="municipio3[][<?php echo $municipio3; ?>]"/> <br/> <?php ++$municipio; ++$municipio2; ++$municipio3; } ?> <input type="submit" value="Enviar"> </p> </form>
lo que necesito es poner los valores de mis array en una tabla llamada departamentos que tiene la siguiente estructura:
cod_empresa
dept1
dept2
dept3
y quiero que el array 1 se guarde en dept1 el array 2 que se guarde en dept2 y el array 3 en dept3 y si se pudiera quisiera guardar directamente en la tabla y no guardar en los arreglos, el formulario lo genero dependiendo del numeor de empresas que contiene la tabla empresas