Retrieve information combobox PHP

3

I want to insert the contents of the combobox into the database via POST, but I can not.

Here is the snippet of the combobox, which pulls the data from a table

    <select name="cmbtimes">
<?php
//pegando os dados
while($dados = mysql_fetch_array($query))
{
     //mostrando eles (dados) em forma de options
?>
     <option value="<?$dados['id'] ?>">
         <?= $dados['time'] ?>
     </option>
<?php

}
?>

And then it goes to the recorder.php page: (the namej is a form text field)

$nomej=$_POST['nomej'];
$cmbtimes=$_POST['cmbtimes'];
$sql = mysql_query("INSERT INTO jogador(nomej, nometime) VALUES('$nomej', '$cmbtimes')");

But it will not):

    
asked by anonymous 08.09.2015 / 20:42

2 answers

2

You have failed to close the select and put the equal sign after the query in value.

Try this:

<select name="cmbtimes">
<?php
//pegando os dados
while($dados = mysql_fetch_array($query))
{
     //mostrando eles (dados) em forma de options
?>
     <option value="<?= $dados['id'] ?>">
         <?= $dados['time'] ?>
     </option>
<?php

}
?>
</select>
    
09.09.2015 / 13:22
3

Very possibly your header is poorly constructed and select is not closed:

<form name="contactForm" method="post" enctype="multipart/form-data" action="cadastrojogador.php">

    <select name="cmbtimes">
<?php
//pegando os dados
while($dados = mysql_fetch_array($query))
{
     //mostrando eles (dados) em forma de options
?>
     <option value="<?$dados['id'] ?>">
         <?= $dados['time'] ?>
     </option>
<?php
}
?>
</select>
</form>

To make sure that the data arrives in the document, the following validation was made in the register.php:

<?php
if(isset($_POST['nomej']))
{
   $nomej=$_POST['nomej'];
   $cmbtimes=$_POST['cmbtimes'];
   $sql = mysql_query("INSERT INTO jogador(nomej, nometime) VALUES('$nomej', '$cmbtimes')");
}
?>
    
09.09.2015 / 18:24