Link to home
Start Free TrialLog in
Avatar of peps03
peps03

asked on

Check if an entered email address exists in 2 tables

Hi,

I have two tables, students and companies which both have a column named email. I need to check if an entered emailaddress exists in the tables.

I tried this:

$query = "select
      NOT EXISTS (select email from students where email = '$email[2]') AND
      NOT EXISTS (select email from companies where email = '$email[2]')";

      $result = mysql_query($query) or die(mysql_error());
      if (mysql_num_rows($result))

But this always returns that the email address already exists.

How should i preform this check correctly?
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

What are you trying to do?

If the email addy exists in neither table, then your SQL statement returns true.  If it exists in at least one of the tables, it returns false.
Avatar of peps03
peps03

ASKER

that is what i am trying. but it always returns false
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peps03

ASKER

Great thanks.

Simple solution, thought there would be some brilliant solution to stuff it into 1 query, but lets unnecessary not complicate thing too much!
@peps03: thanks for the points.  In my experience, the quest for "brilliant solutions" sometimes complicates my life.  So instead I seek solutions that are lazy, pedestrian, simple-stupid and ordinary.  It has been a quest that has repeatedly struck gold, giving me the fastest, most accurate answers.  Thud!  I don't get points at EE by being smarter than anyone else; I get points by plodding along well-traveled paths toward well-defined goals.

All my best, ~Ray