0
I would like a help to validate a field in the form to check if there is already a same email that the user type in the database. When the user clicks on the "register" button he will send directly to the "send.php" page without any validation other than the bootstrap itself. I don’t know if I validated the email field in the.php register itself or in the uploadCadastro.php. I am using PHP PDO to register in the database.
php.
<form action="enviaCadastro.php" method="POST" class="needs-validation" novalidate>
<div class="col-md mb-3">
<input type="email" placeholder="E-mail" id="email" name="email" class="form-control" maxlength="30" required >
<div class="invalid-feedback">Preencha com um e-mail</div><br>
</div>
</form>
envieCadastro.php
session_start(); include_once 'connects Anco.php';
$clicaCadastro = filter_input (INPUT_POST, 'clicaCadastro', FILTER_SANITIZE_STRING);
if($clicaCadastro){
//Pega os dados do form
$nome = filter_input (INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
$sobrenome = filter_input (INPUT_POST, 'sobrenome', FILTER_SANITIZE_STRING);
$datanasc = filter_input (INPUT_POST, 'datanasc', FILTER_SANITIZE_STRING);
$genero = filter_input (INPUT_POST, 'genero', FILTER_SANITIZE_STRING);
$estado = filter_input (INPUT_POST, 'estado', FILTER_SANITIZE_STRING);
$cidade = filter_input (INPUT_POST, 'cidade', FILTER_SANITIZE_STRING);
$email = filter_input (INPUT_POST, 'email', FILTER_SANITIZE_STRING);
$senha = filter_input (INPUT_POST, 'senha', FILTER_SANITIZE_STRING);
//insere no banco de dados
$envia = "INSERT INTO cadastro (nome, sobrenome, nasc, genero, estado, cidade, email, senha) VALUES (:nome, :sobrenome, :datanasc, :genero, :estado, :cidade, :email, :senha)";
$insere_bd = $conecta->prepare($envia);
$insere_bd ->bindParam(':nome', $nome);
$insere_bd ->bindParam(':sobrenome', $sobrenome);
$insere_bd ->bindParam(':datanasc', $datanasc);
$insere_bd ->bindParam(':genero', $genero);
$insere_bd ->bindParam(':estado', $estado);
$insere_bd ->bindParam(':cidade', $cidade);
$insere_bd ->bindParam(':email', $email);
$insere_bd ->bindParam(':senha', $senha);
if($insere_bd->execute()){
header("Location: cadastroRealizado.php");
}else{
header("Location: cadastroErro.php");
}
}else{
$_SESSION ['erro'] = "<p style='color:red;'>Cadastro nao efetuado</p>";
echo "erro ao cadastrar";
}
in case this validation already exists, I wanted one to check if there is already an email registered in the database according to the email that the user put.
– Diego Magalhães