0

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; 
   }   
1
  • question not about wordpress specific
    – newman
    Mar 7, 2018 at 14:22

1 Answer 1

-2

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 *

1
  • So, how would this look? How would I apply that to my current code? 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.