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

Asked

Viewed 134 times

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 will I capture the dice using that statement:

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

Error appears:

Notice: Undefined index: cargo in C: wamp64 www sistema paginas processos cad_clientes.php on line 5

I believe I am doing wrong to get the selected value in the plugin jQuery SELECT2, but I don’t know what’s wrong.

  • Ever tried to give a print_r( $_POST); to verify which variables were passed via POST?

  • Who is $result_city ? And what is $result_situation for ?

  • Change the attribute "name" put it in select and not in options. Also make sure your variables $result_city and $result_situation are correct

1 answer

1


name must be in select <select name = "cidade".... and not in the 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 while does not match, $result_location 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 } ?>
  • Actually the variable was incorrect and the "name" was in the option and the correct one was in the <select>

Browser other questions tagged

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