I made a registration page on my site, which to do the registration needs cpf and email. I made a SELECT to see if it already exists, if yes, not insert, otherwise it does not insert. I left the cpf as pk and email as unique. When I put an existing cpf it shows the alert that I did saying it already exists, but when it is a new cpf and email that is already in the bd, it does not inform and register.
$var1 = $_POST['cpf'];
$var2 = $_POST['email'];
$query = "SELECT * FROM teste WHERE email = '$var2'";
$query = "SELECT * FROM teste WHERE cpf = '$var1'";
$querySelect = mysqli_query($conn, $query);
if (mysqli_num_rows($querySelect) > 0) {
echo"<script type='text/javascript'>alert('Cadastro existente.');window.location.href='cadastro.php';</script>";
}
$var1 = $_POST['cpf'];
$var2 = $_POST['email'];
$sql = 'INSERT INTO teste (cpf, email) VALUES (?,?)';
$stmt = $conn->prepare($sql);
$var1 = $_POST['cpf'];
$var2 = $_POST['email'];
$stmt->bind_param('ss', $var1, $var2);
$stmt->execute();
echo"<script type='text/javascript'>alert('Cadastro realizado com sucesso.');window.location.href='index.php';</script>";
if(!$stmt){
echo 'erro na consulta: '. $conn->error .' - '. $conn->error;
}
And in% w / o I did, I tried to put AND, but it got worse, I did not even check if the cpf was there, I always ended the registration. Can you see any errors?