0
Hello my code is giving error when checking if the result of a function is TRUE, follow the code below:
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Conecxão Falhou: " . $conn->connect_error);
}
echo "Conexao foi um sucesso";
if(VerificaCPF($cpf) === TRUE){
$sql = 'INSERT INTO pessoas VALUES ("'.$nome.'", "'.$cpf.'", "'.$cep.'" , "'.$rua.'", "'.$bairro.'", "'.$cidade.'", "'.$uf.'", "'.$ibge.'")';
//verificando se os valores foram inseridos//
if ($conn->query($sql) === TRUE) {
echo "<br>Os valores foram adicionados corretamente";
} else {
echo "<br>Error: " . $sql . "<br>" . $conn->error;
}
}else{
echo "Os valores nham foram";
}
?>
function VerificaCPF($cpf) {
if (vercpf(document.frmcpf.cpf.value))
{document.frmcpf.submit();}else
{errors="1";if (errors) alert('CPF NÃO VÁLIDO');
document.retorno = (errors == '');}}
function vercpf (cpf)
{if (cpf.length != 11 || cpf == "000.000.000-00" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;
alert('O CPF INFORMADO É VÁLIDO.');
return true;}
This function is not recognized by php pq was set in javascript logo ... remember that javascript works on the client side and php on the server.
– rray
then I would have to check the result by java, or use a php code?
– Nikk 17016
If the Verificacpf function was created in javascript, you can only use it there
– Julyano Felipe
If you want to use it in PHP, you should create it in PHP
– Julyano Felipe
Thanks for the help I’ll finish here.
– Nikk 17016