Jump to content

Messagem de erro


Diana Madeira

Recommended Posts

Boa Noite

 

Estou a criar um formulario de registo e estou quase no fim. para finalizar necessito de ter um código que verique se já existe ou não um usuario com pelo menos o mesmo email.

Creio que consegui isso, mas invez de aparecer a messagem de erro que escrevi,aparecer simplesmente uma mensagem a dizer "duplicate entry....".

 

Alguém me que possa ajudar sff?

deixo aqui o código:

 $sql= "INSERT INTO registo (name, surname, email, doornumber, road, postcode, password) VALUES('".$name."','".$surname."', '".$email."', '".$doornumber."', '".$road."', '".$postcode."', '".$password."')";
        
        $result=mysqli_query($conn,$sql);
        if(!$result){
            die (mysqli_error($conn));
        } else if (mysqli_affected_rows($conn)==0){
            echo "User already exists";
        } else {
            echo '<h3><font color="red">You have successfully registered </font></h3>';
        }

Obrigado

Link to comment
Share on other sites

Aqui está uma possível solução:

 

$sql= "SELECT * FROM registo WHERE email='".$email."'";
        
$result = mysqli_query($conn,$sql);
if(!$result){
    die (mysqli_error($conn));
} else if (mysqli_num_rows($result) > 0){
    echo "User already exists";
} else {
    echo '<h3><font color="red">You have successfully registered </font></h3>';
} 
Edited by 13dev
Erro no sql
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.