I have two registration forms, individual-register.php and school-registration.php. Each one saves data in their own distinct tables. Each one creates its own unique user type (individual and school)

On both of the files I am successfully checking if an email address exists in the database and return and error message if it does. However now I need to checkto make sure that the email address at the time of registration doesn't exist in either of the two tables.

It's peculiar because in the first code block(individual-register.php) it is allowing me to register and it doesn't give me any error at all unless I try with an email addres that I know exists in the table corresponding to that form. I have something similar in teacher-register.php howeer it doesn't allow me to register anything at all and returns an error message even if I enter an email addres that is completely new. Please see the code:


$results_match_email = $wpdb->get_row( 'SELECT * FROM wp_register where 
$check_school_email=$wpdb->get_row( 'SELECT * FROM wp_register_teacher where 

if(count($results_match_email) || count($check_school_email) > 0){

    $lastid = $wpdb->insert_id;


$results_match_email = $wpdb->get_row( 'SELECT * FROM wp_register_teacher 
where schoolemail="'.$_REQUEST['schoolemail'].'"');

$check_individual_email=$wpdb->get_row( 'SELECT * FROM wp_register where 

    if(count($results_match_email) || $check_individual_email) > 0)
      $lastid_teacher = $wpdb->insert_id; 
  • question not about wordpress specific
    – newman
    Commented Mar 7, 2018 at 14:22

1 Answer 1


You had not very good architecture for your application. Best way is in save user information in one table and use separated fields or linked table for save extra information.

In your case you case use UNION and check tables in one query.

And correct way is use SELECT COUNT(*) and check result instead SELECT *

  • So, how would this look? How would I apply that to my current code? Commented Mar 7, 2018 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.