Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Validação de Datas


claytonprog

Question

Olá Pessoal!

Estou com problema, preciso fazer uma validação nas inscricões de cursos.

Vejam o código abaixo:

<?
                         
                                    
                        $id_curso = $_POST['id_curso'];
                        
                        
                        $sql = "select * from cursos where id=$id_curso";                                                        
                        $resultado = mysql_query($sql) or die ("");
                                
                            While($linha = mysql_fetch_array($resultado))
                            {
                                            
                            $curso = $linha['nome'];
                            $valor = $linha['valor'];
                            $vagas = $linha['vagas'];
                                                                        
                            $dt_insc_fin= $linha['dt_insc_fin'];    
                            $data    = explode("-",$dt_insc_fin);
                            $dt_insc_fin = "$data[2]/$data[1]/$data[0]"; 
                                            
                            
                            }
                            
                        
                        ?>

                        <?
                                                
                        $perfil = $_SESSION['id_cliente'];        
                        
                        $sql  = "select * from clientes where id='$perfil'";
                        $query = mysql_query($sql);
                        $dados = mysql_fetch_assoc($query);
                        
                        $nome_usuario = $dados['nome'];
                        $cpf = $dados['cpf'];
                        
                        ?>
                        
                        
                        <!------- Início das Validações de Critérios --->
                        
                        
                        <?php 
                        
                        
                        $sql = "SELECT COUNT( * ) as Total FROM inscricoes WHERE id_curso= '$id_curso'";
                        $resultSet = mysql_query($sql, $conexao);
                        $result = mysql_fetch_array($resultSet);
                        
                                                            
                        if($result['Total'] < $vagas){
                        
                        }                        
                        else
                        
                        {
                        
                        echo "O curso '$curso' não possui mais vagas disponíveis, por favor escolha outra opção de curso!";
                        echo "<br>";
                        echo "<a href='cursos.php'>Voltar!</a><br> ";
                        exit;
                                                                        
                        }
                        
                        ?>
                        <br />
                        
                          
                        
                        <?    
                        
                        
                    [color="#FF0000"]    [b]$new_data = $dt_insc_fin;    
                        $hoje = date("d/m/Y");
                        
                        
                                  
                        
                        if ($hoje >= $new_data){        [/b]    [/color] // erro está aqui                                    
                                
                        echo "Inscrição encerrada, prazo de inscrição para este curso expirado!";
                        
                        echo "<br>";
                        echo "<a href='cursos.php'>Voltar!</a><br> ";
                        exit;
                       
                        }else{
                        
                        
                        
                        }
                        
                        
                        ?>
                        
                        
                        
                        
                        
                        
                     <form action="gravar_inscricao.php" method="post">
                     
                      <input type="hidden" name="id_curso" value="<?echo $id_curso?>">
                      <input type="hidden" name="perfil" value="<?echo $perfil?>">
                      <input type="hidden" name="cpf" value="<?echo $cpf?>">
                        
                          <h2>Usuário:&nbsp;&nbsp;<? echo $nome_usuario; ?></h2>    
                          <br />  
                          
                          <h2>CPF:&nbsp;&nbsp;<? echo $cpf; ?></h2>    
                          <br /> 
                                       
                         <h2>Curso: <?php echo $curso; ?> </h2>                          
                        <br />
                        
                         <h2>Investimento: <?php echo $valor; ?> </h2>                          
                        <br />
                                                                      
                        <h3>
                        
                        Dados para Depósito Bancário:
                         
                         <br />   
                        Agencia: 013-2 | Conta Corrente: 32815-4 <br />
                        Favorecido: A3 Contabilidade, Assessoria e Treinamento 
                        </h3>
                      
                     </p>
                      <p>&nbsp;</p>
                       <input type="submit" value="Confirmar Inscrição" class="button4" name="submit" />
        
                       </form>  
                     
                     
                                          
                      <!------- Final das Validações de Critérios --->

O Grande problema é que quando tento pegar a data de hoje e checar se ela é maior ou igual a do cadastro do curso não está fazendo a validação corretamente, mesmo se data de hoe for maior ele deixa fazer a inscrição ao invés de bloquear e mostra um mensagem.

Se algué puder me ajudar!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Não funcionou!

Mudei isto:

Estava assim:

$dt_insc_fin= $linha['dt_insc_fin'];

$data = explode("-",$dt_insc_fin);

$dt_insc_fin = "$data[2]/$data[1]/$data[0]";

$new_data = $dt_insc_fin;

$hoje = date("d/m/Y");

ficou assim:

$dt_insc_fin= $linha['dt_insc_fin'];

$data = explode("-",$dt_insc_fin);

$dt_insc_fin = "$data[2]-$data[1]-$data[0]";

$new_data = $dt_insc_fin;

$hoje = date("d-m-Y");

comparação de datas:

if ($hoje >= $new_data){

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...