0
In my course system, the instructor has to stipulate the number of students who can enroll in each class and the student will only be able to enroll if the number of students enrolled is lower than the number stipulated by the instructor.
For this I decided to put the comparison on the student registration form in the class, however, as soon as the student enters the page the comparison is not made and already appears the warning "this class is already full".
Student registration form:
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 style="
margin-top:100px;">Inscrição</h1>
<p> </p>
<p class="lead"></p>
<ul class="list-unstyled">
<form id="cadastro" method="post" action="banco/updateP.php" style="
text-align: left;
margin-top:50px;">
<div class="col-lg-12">
<div class="form-group" style="
text-align: left;">
<label for="FORMACAO">Formação: </label>
<input type="text" required class="form-control" id="FORMACAO" name="FORMACAO" value="<?php echo $formacao; ?>">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="TURMA">Turma: </label>
<input type="text" required class="form-control" id="TURMA" name="TURMA" value="<?php echo $turma; ?>">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="COLABORADOR">Colaborador: </label>
<select class="form-control" id="COLABORADOR" name="COLABORADOR">
<option>Selecione...</option>
<?php while($colab = mysqli_fetch_array($queryColaboradores)) { ?>
<option value="<?php echo $colab['NOME']; ?>"><?php echo $colab['NOME']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="AREA">Área: </label>
<select class="form-control" id="AREA" name="AREA">
<option> MITV </option>
<option> CTCA </option>
<option> VSPA </option>
</select>
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="DATA">Data: </label>
<select class="form-control" id="DATA" name="MES">
<option> jan </option>
<option> fev </option>
<option> mar </option>
<option> abr </option>
<option> mai </option>
<option> jun </option>
<option> jul </option>
<option> ago </option>
<option> set </option>
<option> out </option>
<option> nov </option>
<option> dez </option>
</select>
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="PREVISTO">Status: </label>
<input type="text" required class="form-control" id="PREVISTO" name="PREVISTO" value="Previsto">
</div>
<div class="">
<button type="submit" class="btn btn-primary btn-lg btn-block"> <i class="glyphicon glyphicon-floppy-disk"> Salvar </i></button>
</div>
<div class="alert alert-info" role="alert">
<strong>Hey! </strong> Antes de realizar o cadastro, certifique-se de que não se esqueceu de nada! :)
</div>
<?php
//Teste de contador
$limite = "SELECT * FROM turmas WHERE ID = 'TURMA' and NOME = 'FORMACAO'";
$contador = "SELECT COUNT(ID) AS ComparaLIMITE FROM participantes WHERE TURMA = 'turma' and FORMACAO = 'formacao'";
if ($contador <= $limite) {
header("Location: inscricao.php");
}
else {
echo '<script type="text/javascript">
alert("Essa turma estava completa");
window.history.go(-1);
</script>';
}
?>
</div>
</form>
</ul>
</div>
</div>
</div>
This is the database table that saves classes:
ID, NAME, TRAINER, OBJECTIVE, ROOM, DATE, TIME, PLACE, LIMIT
This is the database table that saves entries:
ID, TRAINING, CLASS, COLLABORATOR, AREA, MES, YEAR, PLANNED
Also, the components like page footer, things that appear after my php that has the counter just disappeared from the page.
Can someone help me with this accountant?
Add a
select
before entering data. Ex:SELECT limit FROM table WHERE id = ID-DA-TURMA;
and in thephp
you add a condition. Ex:if ($row->limit >= 5) { /* avisa para o usuário que não há vagas */ } else { /* Cria matricula */ }
– Valdeir Psr
But why 5 if the limit is what I’ll get from the record?
– Mariana Bayonetta
5 is an example. Use LEFT JOIN to return the data from the two tables. The total number and number of registered students.
– Valdeir Psr