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>';
}
?>
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?
– Papa Charlie
edited-check the existence @Papacharlie
– ndroid
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 returnrowCount 0
. Soon0>=0
, or1>=0
... will always display the above message.– Papa Charlie
I understood the logic @Papacharlie Plus what is the obvious solution?
– ndroid
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.
– Papa Charlie
My king, thanks I’m half stopped with php, I’m learning jquery. so I asked this question kind of obvious.
– ndroid
No problem. I tried to make you realize the logic, not to have future mistakes.
– Papa Charlie
Very good, I will go back to studying php, after all it is one of the most important language for programming, until more
– ndroid
@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.
– Bacco
@Papacharlie will come out with an answer?
– Jorge B.
@Bacco, from an old question isn’t it? I think I remember, this example is rolling a long time :)
– Papa Charlie
@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.– Papa Charlie
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.
– Bacco
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
– Bacco