Taking HTML data for a SELECT in another file without POST

Asked

Viewed 64 times

1

Good morning guys, I am starting my life in PHP programming and I have a little 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 that when the user selects the option in the dropdown is made a check if there is in the category table a record that already exists the user And the month, if there is a line where there is already user and month then I put a disable in the fields so that it does not respond more. I made that appointment 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. Thanks in advance!

  • When the user selects an option in select the event is triggered onchange, in this event you must make the request to the verification page.

1 answer

1

Good morning ! , try a search in Ajax, because you are trying to update a screen that depends on a data saved in the database that is on the server, for that 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 !

http://www.devfuria.com.br/javascript/ajax-php-jquery/

  • Oops, thanks a tip man, I’ll take a look, it turns out I need to deliver this day 31, so it’s not a very viable time for me to learn first to then do something... rsrs

Browser other questions tagged

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