PF2G Posted August 13, 2012 at 03:16 PM Report Share #472166 Posted August 13, 2012 at 03:16 PM Boas, eu tenho este codigo: <?php include 'require/db_connect_2.php'; if (isset($_POST['register'])){ $nif=$_POST['nif']; $email=$_POST['email']; $sql_pend="SELECT * FROM user_wait WHERE nif_user_pend='".$nif."' OR email_user_pend='".$email."'"; $result_pend=mysql_query($sql_pend, $connect_2) or die(mysql_error()); $rows_pend=mysql_num_rows($result_pend); if($rows_pend==0){ //fecha ligação mysql_close($connect_2); } else{ echo 'O seu registo está pendente. Verifique a sua caixa de email com o link de ativação.'; } include 'require/db_connect.php'; $sql="SELECT * FROM civil_users WHERE nif_user='".$nif."' OR email_user='".$email."'"; $result=mysql_query($sql, $connect) or die(mysql_error()); $rows=mysql_num_rows($result); if($rows==0){ //fecha ligação mysql_close($connect); } include 'require/db_connect_2.php'; $sql_insert="INSERT INTO user_wait(nif_user_pend, email_user_pend) VALUES('".$nif."', '".$email."')"; $result_send=mysql_query($sql_insert, $connect_2) or die(mysql_error()); if ($result_send){ /******************************* ENVIA EMAIL DE ATIVAÇÃO *******************************/ //e-mail que receber? mensagem $para = $email; $assunto = "Registo - infoCAR"; //cabeçalho $mensagem='LINK ATIVAÇÃO'; $headers = "From: infocar@geral.com\r\n"; $headers .= "Reply-To:".$para."\r\n"; $headers .= "CC: infocar@geral.com\r\n"; $headers .= "BCC: infocar@geral.com\r\n"; //envio do email if(mail($para, $assunto, $mensagem, $headers)) { echo "<script> alert('Foi-lhe enviado um email com um link de ativação.'); location.href='index.php'; </script>"; } /****************************** end/ENVIA EMAIL DE ATIVAÇÃO ******************************/ } } ?> Ele faz o primeiro if: $sql_pend="SELECT * FROM user_wait WHERE nif_user_pend='".$nif."' OR email_user_pend='".$email."'"; $result_pend=mysql_query($sql_pend, $connect_2) or die(mysql_error()); $rows_pend=mysql_num_rows($result_pend); if($rows_pend==0){ //fecha ligação mysql_close($connect_2); } else{ echo 'O seu registo está pendente. Verifique a sua caixa de email com o link de ativação.'; } E está correto, só que no else dá a echo e envia o email, quando nao devia. Alguem me pode ajudar, sff? Obrigado, PF2G Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted August 13, 2012 at 03:20 PM Report Share #472169 Posted August 13, 2012 at 03:20 PM se achas que não deveria apresentar o código dentro do else, então terás de verificar porque é que a condição do if está a falhar se a condição do if é que não tenhas nenhum registo, então entra no else quando tens registos no resultset terás então de verificar quais são esses registos ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
ruimcosta Posted August 21, 2012 at 11:00 AM Report Share #473002 Posted August 21, 2012 at 11:00 AM Boas, eu tenho este codigo: <?php include 'require/db_connect_2.php'; if (isset($_POST['register'])){ $nif=$_POST['nif']; $email=$_POST['email']; $sql_pend="SELECT * FROM user_wait WHERE nif_user_pend='".$nif."' OR email_user_pend='".$email."'"; $result_pend=mysql_query($sql_pend, $connect_2) or die(mysql_error()); $rows_pend=mysql_num_rows($result_pend); if($rows_pend==0){ //fecha ligação mysql_close($connect_2); } else{ echo 'O seu registo está pendente. Verifique a sua caixa de email com o link de ativação.'; } include 'require/db_connect.php'; $sql="SELECT * FROM civil_users WHERE nif_user='".$nif."' OR email_user='".$email."'"; $result=mysql_query($sql, $connect) or die(mysql_error()); $rows=mysql_num_rows($result); if($rows==0){ //fecha ligação mysql_close($connect); } include 'require/db_connect_2.php'; $sql_insert="INSERT INTO user_wait(nif_user_pend, email_user_pend) VALUES('".$nif."', '".$email."')"; $result_send=mysql_query($sql_insert, $connect_2) or die(mysql_error()); if ($result_send){ /******************************* ENVIA EMAIL DE ATIVAÇÃO *******************************/ //e-mail que receber? mensagem $para = $email; $assunto = "Registo - infoCAR"; //cabeçalho $mensagem='LINK ATIVAÇÃO'; $headers = "From: infocar@geral.com\r\n"; $headers .= "Reply-To:".$para."\r\n"; $headers .= "CC: infocar@geral.com\r\n"; $headers .= "BCC: infocar@geral.com\r\n"; //envio do email if(mail($para, $assunto, $mensagem, $headers)) { echo "<script> alert('Foi-lhe enviado um email com um link de ativação.'); location.href='index.php'; </script>"; } /****************************** end/ENVIA EMAIL DE ATIVAÇÃO ******************************/ } } ?> Ele faz o primeiro if: $sql_pend="SELECT * FROM user_wait WHERE nif_user_pend='".$nif."' OR email_user_pend='".$email."'"; $result_pend=mysql_query($sql_pend, $connect_2) or die(mysql_error()); $rows_pend=mysql_num_rows($result_pend); if($rows_pend==0){ //fecha ligação mysql_close($connect_2); } else{ echo 'O seu registo está pendente. Verifique a sua caixa de email com o link de ativação.'; } E está correto, só que no else dá a echo e envia o email, quando nao devia. Alguem me pode ajudar, sff? Obrigado, PF2G Já agora para a boa saúde da tua aplicação, evita os " select * ".... Abraços e beijinhos,Rui Costa Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now