System of registration permission by limit

0

In my course system, the trainer 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 less than the number stipulated by the trainer. p>

For this I decided to put the comparison in the student's registration form in the class, however, once the student enters the page the comparison is not made and already appears the warning "this class is already full". >

Student Enrollment 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 the classes:

  

ID, NAME, TRAINER, OBJECTIVE, ROOM, DATE, TIME, LOCAL, LIMIT

This is the database table that saves the subscriptions:

  

ID, TRAINING, TRAIN, COLLABORATOR, AREA, MONTH, YEAR, EXPECTED ACCOMPLISHED

In addition, the footer-like components of the page, things that appear after my php that has the counter simply disappeared from the page.

Can anyone help me with this accountant?

    
asked by anonymous 24.01.2018 / 15:08

1 answer

0

So that's the part responsible for the comparison:

                             <?php 
                                    $sqlLimite = 'SELECT LIMITE FROM turmas WHERE ID = ' . $turma . ' and NOME = "' . $formacao . '"';
                                    //para retornar resultado
                                    $resultLimite = mysqli_query($connection, $sqlLimite);
                                    //para trazer resultados no formato array
                                    $limite = mysqli_fetch_array($resultLimite);

                                    //seleciona todos os registros quando turma = $turma e formacao = $formacao
                                    $sqlcontador = 'SELECT * FROM participantes WHERE TURMA = ' . $turma . ' and FORMACAO = "' . $formacao . '"';
                                    //para retornar o resultado
                                    $result = mysqli_query($connection, $sqlcontador);
                                    //contar quantos registros foram retornados
                                    $contador = mysqli_num_rows($result);

                                    if ($contador < $limite['LIMITE']) { 
                                        header("Location: inscricao.php"); 
                                        } 
                                    else { 
                                        echo '<script type="text/javascript">
                                                alert("Essa turma está completa");
                                                window.history.go(-1);
                                            </script>';
                                        }
                              ?>
    
25.01.2018 / 13:14