0
I have a database that is filled with data coming from the database and I wanted that after pressing the button, that chosen information to go to the database. Whenever I try to send the data I have in the textbox without using the combobox works, from the moment in use the combobox no longer works. I tried to send the value of the combobox to a textbox and from there record, but I also could not make it 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 main code is:
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >
<label>Data:</label>
<input type="date" name="data_marcacao">      
<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">
    <label><b><font size=4>Observações:</font></b>
</label> <br>
    <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>
I’ve already edited the code on top, for how I’m using it now but it still doesn’t... It’s not connecting to the database and I can’t figure out why, if I take the information part of the combobox it’s working...
– Isabel Sousa
There are a few things to consider, for example: Does the bank have the 'specialty' column? Accept the amount you are passing?
– Isaias Lima
It is already solved.. Another thing, I have an input type time, but it is not compatible with the time attribute of the database table... Is there any way around that?
– Isabel Sousa
If you want to convert to timestamp, normally the field already returns in the default value for this, type: $data = strtotime($_POST['data']);. If not, you need to make the field value YYYY-MM-DD to use this command. If you want to convert this timestamp into datetime, just make $dt = date('Y/m/d h:i:s', $data);
– Isaias Lima
I recommend not using the time field as not all browsers have support (read microsoft)
– Isaias Lima
I have another way to do this, but I needed to know how to do a query where I want what is not in the database, I mean, I have a few hours marked in the database and I want a query where I see all the other hours that are not yet scheduled.. This is possible?
– Isabel Sousa
You will have to make a temporary table of possible hours, and do a NOT IN of the hours that is in your target table, type: SELECT TIME FROM #tabletime NOT IN (SELECT DISTINCT TIME FROM tabletarget)
– Isaias Lima