0
Hello, I’m putting together a system for the college project. I have a relationship between City-State. Well, the state CRUD is already working and storing in the Database, when I will register a city, this city needs a registered state, so the fields to register the city.
"City name"(input type text) and UF(Combobox already populated through a select) When I try to store in the bank the name of the city and the state coming from a combobox does not appear anything in the bank, even pointing no error. How I perform the db Insert using a state in the combobox
<?php
include 'inc/funcoes.php';
$banco = abrirBanco();
?>
<html>
    <head>
        <title>Cadastro de Cidade</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <form name="Cidade" action="inc/funcoes.php" method="POST">
            Nome da Cidade:
            <input type="text" name="cidade" size="30" />
            UF:
            <select name="estados">
                <option value="">Selecione</option>
                <?php
                $sql = "SELECT * FROM estado";
                $resultado = $banco->query($sql);
                while($row_estados = $resultado->fetch_array()){ 
                ?>
                <option value="<?=$row_estados['idestado']?>"><?=$row_estados['nomeestado']?></option>
                <?php
                }
                ?>
            </select><br><br>
            <input type="hidden" name="acao" value="inserirCidade"/>
            <input type="submit" value="Cadastrar Cidade">
            <input type="reset" value="Limpar Dados">
        </form>
    </body>
</html>
Function of stand of combobox Line:17 - 26

In this code you showed, you’re not entering anything into the database.
– Francisco
The table
cidadehas the column for the foreign keyestado?– Woss
was recording with the wrong name in the table, but to simplify I decided to do as the friend below said, using a function in javascript to fetch the combobox data
– Gian Carlo Mdr