0

Hi,

i'm doing a validation of registration form, and i'm checking if there's the same username and email:

$query_verify_email = "SELECT * FROM alunos WHERE username ='".$username."' AND email_aluno='".$email."'";
        $result_verify_email = mysql_query($query_verify_user, $connect);
        
		//if the Query Failed ,similar to if($result_verify_email==false)
if (!$result_verify_email)

How do i do both checks separated?

Does the AND operator works, like:

$query_verify_user= "SELECT * FROM alunos WHERE username ='".$username."'";
        $result_verify_user = mysql_query($query_verify_email, $connect);

$query_verify_email = "SELECT * FROM alunos WHERE email_aluno='".$email."'";
        $result_verify_email = mysql_query($query_verify_email, $connect);

        
		//if the Query Failed ,similar to if($result_verify_email==false)
if (!$result_verify_user AND $result_verify_email)

Can someone help me?

Thank you,
PF2G

Edited by PF2G: n/a

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by masterjiraya
0

No the AND operator doesn't work like that it needs to be &&.

You are also missing the ! at the start of $result_verify_email in the if statement.

Why do you want to split into 2 queries anyway?

0

AND is for mysql syntax search operator basically in the where clause. but in your case you cannot use AND. && is what you need for logical comparisons
but in the case you want to separate the query in to syntax queries Isuggest you do this.

<?php
if(isset($username)){
$query_verify_user= "SELECT * FROM alunos WHERE username ='".$username."'";
        $result_verify_user = mysql_query($query_verify_email, $connect);
//verifying the query for the second time
if(isset($email)){
$query_verify_email = "SELECT * FROM alunos WHERE email_aluno='".$email."'";
        $result_verify_email = mysql_query($query_verify_email, $connect);
//flag for boolean
$comapareIdentical=false;
if($result_verify_email==$result_verify_user){
//what ever action you want goes here
$compareIdentical=true;
}
}}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.