How to check if a value exists in one of two database tables

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:

individual-register.php

$results_match_email = $wpdb->get_row( ‘SELECT * FROM wp_register where
artistemail=”‘.$_REQUEST[‘artistemail’].'”‘);
$check_school_email=$wpdb->get_row( ‘SELECT * FROM wp_register_teacher where
schoolemail=”‘.$_REQUEST[‘schoolemail’].'”‘);

if(count($results_match_email) || count($check_school_email) > 0){
$insert_save=0;
}

else{
$insert_save=$wpdb->insert(“wp_register”,$insert_reg);
$lastid = $wpdb->insert_id;
}

teacher-register.php

$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
artistemail=”‘.$_REQUEST[‘artistemail’].'”‘);

if(count($results_match_email) || $check_individual_email) > 0)
{
$insert_save=0;
}
else
{
$insert_save=$wpdb->insert(“wp_register_teacher”,$insert_reg);
$lastid_teacher = $wpdb->insert_id;
}

Read more here:: How to check if a value exists in one of two database tables

Leave a Reply

Your email address will not be published. Required fields are marked *