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!