How to pass selected information in the combobox to the database?

0

I have a database that is populated with data coming from the database and I wanted it to click on the button, that information was chosen for the database. Whenever I try to send the data I have in the textbox without using the combobox it works, from the moment in use the combobox no longer gives. I tried to send the value of the combobox to a textbox and from there I did not get it to work.

This is the code called, to the main page:

....
if (isset($_POST['botao_marcar']))
{

     $data = trim($_POST['data_marcacao']); 
     $hora = trim($_POST['hora_marcacao']);
     $especialidade= trim($_POST['cbEspecialidade']);
     $observacoes= trim($_POST['observacoes']);


     $sql = "INSERT INTO Consulta_marcada (data, hora_inicio, especialidade observacoes) VALUES ('".$data."', '".$hora."', '".$especialidade."','".$observacoes."')";

....

The primary code is:

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >
<label>Data:</label>
<input type="date" name="data_marcacao"> &nbsp &nbsp &nbsp 

<label>Hora:</label>
<input type="time" name="hora_marcaçao">

....
$query = "SELECT especialidade FROM Medicos";
$data = mysqli_query($dbconn, $query);
$result = mysqli_num_rows($data);       

?>

<form name="especialidades" method="post" action="">
<label for="cbEspecialidade">Selecione um Medico</label>
<select id="cbEspecialidade" name="cbEspecialidade">
<option>Selecione...</option>

<?php while($prod = $data->fetch_assoc()) { 
    echo '<option 
value="'.$prod['especialidade'].'">'.$prod['especialidade'].'</option>';
}
?>    
</select>

....

<div id="observacoes">
&nbsp &nbsp <label><b><font size=4>Observa&ccedil;&otilde;es:</font></b>
</label> <br>
&nbsp &nbsp  <textarea type="text" id="observacoes" value="" rows="3" cols="87" maxlength="50"> </textarea>
</div>

<br>
<br>
<div id="botao">
  <input type="submit" name="botao_marcar" value="MARCAR CONSULTA" class=botaoEnviar /> 
</div>  
</form>
    
asked by anonymous 28.06.2017 / 17:59

1 answer

0

From what I'm seeing in your code, the Specialty select does not have the name attribute, besides that in PHP you're looking for a different name that is in HTML.

Include the name attribute in select and call in PHP with the same value, for example "cbSpeciality" as it is in attribute ID

    
28.06.2017 / 19:41