2
the email field in the database is Unique
<?php
require_once("conexao.php");
$nome = $_REQUEST['nome'];
$email =$_REQUEST['email'];
$telefone = $_REQUEST['telefone'];
try{
$conexao = new PDO($banco,$user,$senha);
$sql = "INSERT INTO tb_crud2 (nome,email,telefone) VALUES ('$nome','$email','$telefone')";
$registro = $conexao->query($sql);
$row = $registro->rowCount();
if ($row==1){
echo "cadastrado com sucesso";
}else{
echo "este email já está cadastrado em nosso banco de dados";
}
}catch (PDOException $e){
echo "erro ao se conectar";
}
Bad solution using select. Unique is just to avoid having to do this check first, so there’s no reason to do it. Analyze the return of the Insert and, if necessary, the error code, is the best and only it would be enough to answer.
– Woss
Ah, just gave as option, also do not like the option of select pq can have problems with competition. msm email can be inserted between select and Insert.
– Francisco