How to verify the existence of email?

Asked

Viewed 230 times

1

I am inserting users into database and when clicking on "Submit" in the form says to enter the email and this email already exists.

I’ve been analyzing I’ve changed [rowCount()>=0] for [rowCount()>=1] ,gave

Internal error 1 when checking email

That is, never validates the email , I am grateful!

require_once( '../../site/classes/DB.class.php' );

if($_SERVER['REQUEST_METHOD'] == 'POST' ) {
  $email =     $_POST['email'];
  $erro = '';


 $verificar = DB::getConn()->prepare("SELECT `id` FROM `usuarios` WHERE `email`=?");

  if( $verificar->execute( array( $email) ) ) {
     if( $verificar->rowCount()>=0){
        $erro .= 'Este e-mail ja existe<br>';
     } else {
        $erro .= 'Erro interno 1 ao verificar o e-mail<br>';
     }
  } else {
     $erro .= 'Erro interno 2 ao verificar o e-mail<br>';
  }

?>

  • 1

    Internal error 1 when checking email this does not exist, or the email is registered or not - this condition does not indicate error because it is a behavior expected. What you want to do is, validate an email, or check if it exists?

  • edited-check the existence @Papacharlie

  • 1

    Understand: rowCount()>=0 means that if the query is zero or greater than zero, it will display This e-mail already exists. A query for a non-existent email will return rowCount 0. Soon 0>=0, or 1>=0... will always display the above message.

  • I understood the logic @Papacharlie Plus what is the obvious solution?

  • Apparently you didn’t understand, but your answer is here. Just copy the code. I’m leaving the link because your code is more wrong than you think.

  • My king, thanks I’m half stopped with php, I’m learning jquery. so I asked this question kind of obvious.

  • No problem. I tried to make you realize the logic, not to have future mistakes.

  • Very good, I will go back to studying php, after all it is one of the most important language for programming, until more

  • @Papacharlie actually this was supposed to be a debug of the code in the previous question to see if we were getting there, but in the end I forgot to detail this in the relevant question. Now I put a comment on the other answer to be more evident.

  • @Papacharlie will come out with an answer?

  • @Bacco, from an old question isn’t it? I think I remember, this example is rolling a long time :)

  • @Jorgeb., I didn’t think to give a definitive answer, I closed the link I recommended. If you want to talk about it. This query can be exchanged for a count and a fetch. I pass the ball.

  • 3

    I think I better close this after solving, because the problem was in the previous one (otherwise it will be more of this type hanging on the site) @Lamborghiniaventador see the original question, I got there.

  • I fixed the ">", which I copied from the original code and didn’t even notice, and put a descriptive comment in place of the "Else". I had rewritten the whole code, and I ended up distracting in this piece. http://answall.com/a/34161/70

Show 9 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.