Hedi 2 Denunciar post Postado Março 31, 2006 estou fazendo uns testes aqui com validação de formulaio, mas tenho duvida do metodo que utilizo, nao sei se e a melhor forma. vejam: <?php include("conecta.php");$nome=$_POST['usunome'];$cpf=$_POST['usucpf'];$rg=$_POST['usurg'];$nasc=$_POST['usunasc'];$cidade=$_POST['usucidade'];$estado=$_POST['usuestado'];$end=$_POST['usuend'];$bairro=$_POST['usubairro'];$num=$_POST['usunum'];$cep=$_POST['usucep'];$email=$_POST['usuemail'];$usuario=$_POST['usuusu'];$senha=$_POST['ususenha'];$confsenha=$_POST['usuconfsenha'];$perg=$_POST['usuperg'];$resp=$_POST['usuresp'];$confresp=$_POST['usuconfresp'];//verifica nomeif((strlen($nome)>40) || (empty($nome))){header("Location:cadastro.php?erro=001");}//verifica cpfelseif((empty($cpf)) || (strspn($cpf,"0123456789") != strlen($cpf)) || (strlen($cpf)>11)){ header("Location:cadastro.php?erro=002");}//verifica rgelseif((empty($rg)) || (strspn($rg,"0123456789") != strlen($rg)) || (strlen($rg)>15)){ header("Location:cadastro.php?erro=003");}//verifica data nascelseif((empty($nasc)) || (strspn($nasc,"0123456789/") != strlen($nasc)) || (strlen($nasc)>10)){ header("Location:cadastro.php?erro=004");}//verifica cidadeelseif((empty($cidade)) || (strlen($cidade)>30)){ header("Location:cadastro.php?erro=005");}//verifica estadoelseif((empty($estado)) || (strlen($estado)>2)){ header("Location:cadastro.php?erro=006");}//verifica endereçoelseif((empty($end)) || (strlen($end)>50)){ header("Location:cadastro.php?erro=007");}//verifica bairroelseif((empty($bairro)) || (strlen($bairro)>30)){ header("Location:cadastro.php?erro=008");}//verifica numeroelseif((empty($num)) || (strlen($num)>8)){ header("Location:cadastro.php?erro=009");}//verifica numeroelseif((empty($cep)) || (strlen($cep)>8)){ header("Location:cadastro.php?erro=022");}//verifica e-mailelseif ((empty($email)) || (!preg_match("/@.*.\./",$email))){header("Location:cadastro.php?erro=010");}//verifica usuarioelseif((empty($usuario)) || (strspn($usuario,"abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY_0123456789") != strlen($usuario)) || (strlen($usuario)>8) || (strlen($usuario)<4)){ header("Location:cadastro.php?erro=011");}//verifica senhaelseif((empty($senha)) || (strspn($senha,"abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY_0123456789") != strlen($senha)) || (strlen($senha)>8) || (strlen($senha)<4)){ header("Location:cadastro.php?erro=012");}//verifica conf senhaelseif($senha != $confsenha){ header("Location:cadastro.php?erro=017");}//verifica perguntaelseif((empty($perg)) || (strlen($perg)>40)){ header("Location:cadastro.php?erro=013");}//verifica resposta perguntaelseif((empty($resp)) || (strlen($resp)>15) || (strlen($resp)<4)){ header("Location:cadastro.php?erro=014");}//verifica confirmação resposta perguntaelseif($resp != $confresp){ header("Location:cadastro.php?erro=018");}else{//else1 $verifica=true; //verifica se nao há usuario ou email repetidos $query = "SELECT usu_email,usu_usu FROM usuario WHERE usu_email='$email' OR usu_usu='$usuario'"; $query = mysql_query($query) or die(mysql_error()); while ($linha = mysql_fetch_array($query)) { $veremail = $linha['usu_email']; $verusuario = $linha['usu_usu']; if($veremail==$email){ $verifica=false; header("Location:cadastro.php?erro=015"); } if($verusuario==$usuario){ $verifica=false; header("Location:cadastro.php?erro=016"); } } if($verifica==true){ $resp=md5($resp); $senha=md5($senha); $query = "INSERT INTO usuario (usu_nome,usu_cpf,usu_rg,usu_nasc,usu_cidade,usu_estado,usu_end,usu_bairro,usu_num,usu_cep,usu_email,usu_usu,usu_senha,usu_perg,usu_resp) VALUES ('$nome','$cpf','$rg','$nasc','$cidade','$estado','$end','$bairro','$num','$cep','$email','$usuario','$senha','$perg','$resp')"; $result = mysql_query($query) or die(mysql_error()); header("Location:logar.php"); } mysql_close($conexao); }//fecha else 1?> Compartilhar este post Link para o post Compartilhar em outros sites
marceloy 0 Denunciar post Postado Março 31, 2006 Eu gosto de usar Expressões Regulares na validação de formulários. Dê uma olhada em: http://br2.php.net/manual/pt_BR/function.ereg.php Compartilhar este post Link para o post Compartilhar em outros sites