I'm using this function in my form but I have a problem.
It is validating the field and is not including in the bd, but the message instead of saying that the client already exists is saying that it was successfully registered.
How to fix this? ... if it already exists in BD it informs that the client already exists and if it does not exist it informs that it has been registered?
My code looks like this:
$search = mysql_query("SELECT * FROM clientes WHERE cnpj = '$cnpj'");
if(@mysql_num_rows($search) > 0){
echo 'Esse Cliente já existe';
}else
// faz inserção
mysql_query("INSERT INTO clientes (dia,mes,ano,data2,nome,fantasia,contato,fone,celular,email,cnpj,estadual,endereco,cep,bairro,cidade,estado,nf,desconto,obs) values
('$dia','$mes','$ano','$data2','$nome','$fantasia','$contato','$fone','$celular','$email','$cnpj','$estadual','$endereco','$cep','$bairro','$cidade','$estado','$nf','$desconto','$obs')");
}
}
echo '<script type="text/javascript">
alert("Registro Incluído com Sucesso!!!");
</script>';
//Atualize a página
echo
'<script type="text/javascript">location.replace("clientes.php");</script>';