Get an HTML data for a SELECT in another file without POST

1

Good morning, I'm starting my PHP programming life and I have a problem here. I have the following form:

<form action="cadastro_pex.php" method="post">
<label>Período:
  <select name="periodo" id="periodo" style="text-transform: capitalize;">
        <option <option value="" disabled selected>Selecione...</option>
    <?php foreach ($ids_mes as $index => $id_mes) { ?>
        <option value="<?= $id_mes ?>"><?= $meses[$index] ?></option>
    <?php
      }
    ?>
  </select>
</label>
<input name="id_franqueado" type="hidden" value="<?php echo $id_franqueado?>" id="id_franqueado" />

I need when the user selects the option in the dropdown a check is made if there is in the table category a record that already exists the user AND the month, if there is a line where there already exists same user and month, I place a disable in the fields so he does not answer any more. I made this query like this:

$sql = "SELECT * FROM categoria1 WHERE franqueados_id_franqueados = 'id_franqueado' AND periodo_id_periodo = 'periodo' ";
$result = mysqli_query($conexao, $sql);


if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $id_franqueado_consulta = $row["franqueados_id_franqueados"];
        $id_data_consulta = $row["periodo_id_periodo"];
    }
    if ($id_franqueado_consulta == '$_POST[id_franqueado]' && $id_data_consulta == '$_POST[id_periodo]') {
        echo "Teste";
    }
} 

mysqli_close($conexao);

I hope you can help me. Thank you!

    
asked by anonymous 26.01.2018 / 15:06

1 answer

0

Good morning !, try to search Ajax, because you are trying to update a screen that depends on a data saved in the database that is on the server, for this you need to make a simple request in javascript.

I will leave a link for you to give a read on this subject, it is not difficult and once you understand will always use!

link

    
26.01.2018 / 15:21