PHP - Receiving the ID of a value via select option $_POST

Asked

Viewed 349 times

0

Good afternoon guys, I’m developing a code.

I need to get a value to register it as fkid of a table.

I have that part of the code:

    <td><h3>Vincular Conteudo</h3></td>
    <td colspan="2"><select name="tipoConteudo" class="form-control">
    <?php
        $tipoConteudo = new ConteudoDAO($conexao);
        foreach($tipoConteudo->listaNomeConteudo() as $tipo) : 
    ?>
            <option value="<?=$tipo['nomeConteudo']?>"> 
                <?=$tipo['nomeConteudo']; ?> 
            </option> 
        <?php 
        endforeach
        ?>

This part of the code works perfectly. It demonstrates a dropdown of what I need. But I need to send the id linked to the "Conteur name", which belongs to the table content. I will demonstrate the function listNomeConteud below:

function listaNomeConteudo() {
    $conteudos = array();
    $query = "select * from conteudo";
    $resultado = mysqli_query($this->conexao, $query);

   while($conteudo = mysqli_fetch_assoc($resultado)){
        array_push($conteudos, $conteudo);
    }
    return $conteudos;
}

All I need to do is take the line ID nameConteud, and link to a new table like fkid.

Could anyone help me? Thank you

  • Note that when I try to get the value per post of typeConteud, it returns only "ARRAY"

1 answer

3


In that part:

<option value="<?=$tipo['nomeConteudo']?>"> 
                <?=$tipo['nomeConteudo']; ?> 
            </option> 

Why are you passing 'dateName' in value? Why don’t you pass the ID?

  • Dude, you know that moment where you look at your code and it looks like it’s all right? It really solved my problem. Thank you.

  • 1

    It happens. It has already rolled many times with me haha. If you can, just favorite my answer. Hugs!

  • @Andrémolinari from what I realized the response of Cayo is correct. Only you can mark it as a right answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.