php:通过mysql获取选项选择值

I'm trying to have an altas.php file for various html forms. This code is a html form with some mysql columns:

<div><label for="categoria">Categoría principal</label><select type="text" name="categoria">
        <?php 
            $query = "select id, categoria from categorias";
            $result = mysqli_query($mysql,$query);
            if(!$result) echo 'Muy mal....';
            $num_filas = mysqli_num_rows($result);
            for ($i = 0; $i < $num_filas; $i++){
                $row = mysqli_fetch_array($result);
        ?>
        <option value "<?php echo $row['id']?>"><?php echo $row['categoria']?></option><?php
            }   
        ?>
        </select></div>

On the other hand, if I make this:

foreach($_POST as $campo => $valor){
        echo $campo ." = ". $valor ."
";
    }

I have no data in $row['categoria']. It should return the value, which is the categorias's id.

Another question:

How can I use the "foreach" whith an insert sentence?

For example:

 foreach($_POST as $campo => $valor){
$query ="INSERT INTO $tabla ($campo) VALUES ('$valor')";
}

$tabla is sent via $_GET. This code make a new row for each $campo. Any idea?

I have try some suggestions, but nothing works.

You seem to be missing an = and closing semi-colons on this line:

<option value "<?php echo $row['id']?>"><?php echo $row['categoria']?></option><?php

Should be:

<option value="<?php echo $row['id']; ?>"><?php echo $row['categoria']; ?></option><?php

EDIT: Also removed type from select list