php - Check if email is in either of two tables -
i want check if email entered in form belongs either of 2 tables: clients , students. if exists in either, want stop process. i'm not sure i'm going wrong following code:
$email = $_post['email']; $sqlcheckemail = " select * students inner join clients b on a.email = b.email a.email = '$email' "; $querycheckemail = $connection->query($sqlcheckemail); $rowexists = mysqli_num_rows($querycheckemail); if( $rowexists > "0" ){ echo "<h1>error: email exists in database! <br> redirecting......</h1>"; header('refresh: 2;url=../pages/register.php'); exit(); }
you're using join
condition looks matching emails in both tables. need use union
:
$sqlcheckemail = "(select * students email = '$email') union (select * clients email = '$email')";
obviously, may need tweak above if columns don't match (you need same number of columns in both select
statements and, if want results make sense, want them same types of data).
note: wide open sql injection. need use prepared statements, not direct evaluation of variables $email
. (but not only) true when data user, $email = $_post['email'];
.
one more thought: $rowexists > "0"
may work, doesn't make sense. $rowexists
integer. compare 0
, not "0"
.
Comments
Post a Comment