0
I made a registration page on my website, which to register needs Cpf and email. I made a SELECT to see if it already exists, if yes, do not enter, otherwise do not enter. I left Cpf as pk and email as Unique. When I put an existing Cpf it shows the Alert I did saying that 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 the SELECT
that I did, I tried to put AND, but it got worse, I didn’t even check if Cpf was there, I always completed the register. You can see some mistake?
pq does not make a query with only one
OR
verifyingemail
andcpf
If you have any record it is because either of the two already exists. There is a lot of code repeated there O.o– rray
Really kkkkk my code gets a mess at first, but then I fix everything
– Maria