How do I send a selected Data in SELECT2 by method = POST?

0

I have the following code:

<label>Cidade</label>
<select class="form-control select2 select2-hidden-accessible" style="width:100%;" tabindex="-1" aria-hidden="true">
<option selected="selected" value = "0">Selecione</option>
<?php
$result_situacao = "SELECT * FROM 'tabela_cidades'";
$con = $conn->query($result_cidade) or die($conn->error);
while($dado = $con->fetch_array()){ ?>
<option value="<?php echo $dado['id_cidades']; ?>" name = "cidade"><?php echo $dado['nome_cidades']; ?></option>
<?php } ?>

But when I will capture the data using this statement:

  

$ id = mysqli_real_escape_string ($ conn, $ _POST ['city']);

The error appears:

  

Notice : Undefined index: title in C: \ wamp64 \ www \ system \ pages \ processes \ cad_clients.php on line 5

I think I'm doing it wrong to get the value selected in the jQuery SELECT2 plugin, but I do not know what's wrong.

    
asked by anonymous 30.03.2017 / 19:33

1 answer

1

The name should be in select <select name = "cidade".... and not in option

Sintaxe:
 <select name="NOME" size="ALTURA">
   <option value="VALOR A PASSAR">VALOR MOSTRADO</option>
   <option value="VALOR A PASSAR">VALOR MOSTRADO</option>
   <option value="VALOR A PASSAR">VALOR MOSTRADO</option>
 </select>
<label>Cidade</label>
<select name = "cidade" class="form-control select2 select2-hidden-accessible" style="width:100%;" tabindex="-1" aria-hidden="true">
<option selected="selected" value = "0">Selecione</option>

The variable in the while does not match, $ result_situation and not $ result_city OR VICE-VERSA

<?php
$result_situacao = "SELECT * FROM 'tabela_cidades'";
$con = $conn->query($result_situacao) or die($conn->error);
while($dado = $con->fetch_array()){ ?>
<option value="<?php echo $dado['id_cidades']; ?>"><?php 
echo $dado['nome_cidades']; ?></option>
<?php } ?>
    
30.03.2017 / 20:14