Validação de cpf não func
Olá colegas, estou usando um script de validação de CPF q não tá funcionando. alguém pode me ajudar?
<?php
function converter_data($strData) {
// Recebemos a data no formato: dd/mm/aaaa
// Convertemos a data para o formato: aaaa-mm-dd
if ( preg_match("#/#",$strData) == 1 ) {
$strDataFinal = implode('-', array_reverse(explode('/',$strData)));
}
return $strDataFinal;
}
?>
<?php
$pg=$_POST['txt_pg'];
$cpg=$_POST['txt_cpg'];
$nome=$_POST['txt_nome'];
$nomeguerra=$_POST['txt_nomeguerra'];
$qdo=$_POST['txt_quadro'];
$esp=$_POST['txt_esp'];
$qe="$qdo/$esp";
$dnasc=converter_data($_POST['txt_dnasc']);
$dpraca=converter_data($_POST['txt_dpraca']);
$endereco=$_POST['txt_endereco'];
$bairro=$_POST['txt_bairro'];
$fone=$_POST['txt_fone'];
$cep=$_POST['txt_cep'];
$pai=$_POST['txt_pai'];
$mae=$_POST['txt_mae'];
$saram=$_POST['txt_saram'];
$pasep=$_POST['txt_pasep'];
$cpf=$_POST['txt_cpf'];
$rg=$_POST['txt_rg'];
$om=$_POST['txt_om'];
$divisao=$_POST['txt_divisao'];
$setor=$_POST['txt_setor'];
$dmov=converter_data($_POST['txt_dmov']);
$dapres=converter_data($_POST['txt_dapres']);
$dultprom=converter_data($_POST['txt_dultprom']);
$antiguidade=$_POST['txt_antiguidade'];
$ra=$_POST['txt_ra'];
$situacao=$_POST['txt_situacao'];
$religiao=$_POST['txt_religiao'];
//VERIFICA SE O QUE FOI INFORMADO É NÚMERO
if(!is_numeric($cpf)) {
$status = false;
}
else {
//VERIFICA
if( ($cpf == '11111111111') || ($cpf == '22222222222') ||
($cpf == '33333333333') || ($cpf == '44444444444') ||
($cpf == '55555555555') || ($cpf == '66666666666') ||
($cpf == '77777777777') || ($cpf == '88888888888') ||
($cpf == '99999999999') || ($cpf == '00000000000') ) {
$status = false;
}
else {
//PEGA O DIGITO VERIFIACADOR
$dv_informado = substr($cpf, 9,2);
for($i=0; $i<=8; $i++) {
$digito[$i] = substr($cpf, $i,1);
}
//CALCULA O VALOR DO 10º DIGITO DE VERIFICAÇÂO
$posicao = 10;
$soma = 0;
for($i=0; $i<=8; $i++) {
$soma = $soma + $digito[$i] * $posicao;
$posicao = $posicao - 1;
}
$digito[9] = $soma % 11;
if($digito[9] < 2) {
$digito[9] = 0;
}
else {
$digito[9] = 11 - $digito[9];
}
//CALCULA O VALOR DO 11º DIGITO DE VERIFICAÇÃO
$posicao = 11;
$soma = 0;
for ($i=0; $i<=9; $i++) {
$soma = $soma + $digito[$i] * $posicao;
$posicao = $posicao - 1;
}
$digito[10] = $soma % 11;
if ($digito[10] < 2) {
$digito[10] = 0;
}
else {
$digito[10] = 11 - $digito[10];
}
//VERIFICA SE O DV CALCULADO É IGUAL AO INFORMADO
$dv = $digito[9] * 10 + $digito[10];
if ($dv != $dv_informado) {
$status = false;
}
else
$status = true;
}//FECHA ELSE}//FECHA ELSE(is_numeric)
if($status==true) {
$sql = "SELECT * FROM efetivo WHERE nomeguerra = '".$nomeguerra."' AND saram = '".$saram."' ";
$query = mysql_query($sql);
$total = mysql_num_rows($query);
//se a busca nao retornou nenhum registro
if($total == 0) {
$sql = "INSERT INTO efetivo (pg, cpg, nome, nomeguerra, qe, d_nasc, d_praca, endereco, bairro, fone, cep, pai, mae,saram, pasep, cpf, identidade, om, divisao, setor, d_mov, d_apres, d_ultprom, antiguidad, rarc, situacao,
religiao) VALUES ('$pg','$cpg','$nome','$nomeguerra','$qe','$dnasc','$dpraca','$endereco','$bairro','$fone',
'$cep','$pai','$mae','$saram','$pasep','$cpf','$rg','$om','$divisao','$setor','$dmov','$dapres','$dultprom',
'$antiguidade','$ra','$situacao','$religiao')";
$resultado = mysql_query($sql)
or die (mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>::. SISPES - CADASTRO .::</title>
<link href="estilo_sispes.css" rel="stylesheet" type="text/css" />
<style type="text/css"><!--
.style2 {
color: #FFFFFF;
font-weight: bold;
font-size: 18px;
}-->
</style>
</head>
<body>
<b>
<div align="center"><img src="Imagens/comar2.gif" width="70" height="76" /><br />
<br />
DIVISÃO DE RECURSOS HUMANOS<br />
SEÇÃO DO PESSOAL MILITAR<br />
<span class="style1">SISTEMA DE PESSOAL</span></div>
<label>
<?php
echo "<BR><BR><BR><center>Dados inseridos com sucesso!</center>";
}
else if ($total<>0) {
echo "<br><br><br><center>Militar já cadastrado !!!</center>";
}
else if ($status<>true){
echo "<br><br><br><center>o CPF '".$cpf."' é inválido!!!";
}
}
?>Discussão (2)
Carregando comentários...