Login with two tables

0

Gale I do not know if I did it right, I have 2 users, admin and distributor, I created 2 tables, I do not know if I did the correct one, admin has only id name email and password, since the distributor has id name email password and other fields more .... is it correct to create 2 distinct tables, or a single table for the 2 users? As I did 2 tables, I packed the following: I just logged in with a table ... but I need the 2 users to log in ..

A CRUD of life looks like this:

public function select($fields,$table,$cond,$exec){
    $this->prepExc('SELECT '.$fields.' FROM '.$table.' '.$cond.' ',$exec);
    return $this->query;
}

I have this login class:

$this->log = $this->senha == $senha?
        $this->crud->select('*','administrador','WHERE email = ? && senha = ?',array($this->email,$this->cpt->setCripto($this->senha))):
        FALSE;

how can I sign in this case with 2 tables?

    
asked by anonymous 06.11.2016 / 01:28

2 answers

0

You can then do the following:

Check in table A, if email and password exist, if true, check if they are correct, return false, pass the next check in table B, or return false.

Example:

$consultaA = mysqli_query($conexao, "
    SELECT * FROM 
        tabela1 
    WHERE 
        email = '".$_POST['email']."' 
    AND 
        senha '".$_POST['senha']."'
");

if(mysqli_num_rows($consultaA)>0){  
    echo "Logar Administrador"; 
} else {
    $consultaB = mysqli_query($conexao, "
        SELECT * FROM 
            tabela2 
        WHERE 
            email = '".$_POST['email']."' 
        AND 
            senha '".$_POST['senha']."'
    ");

    if(mysqli_num_rows($consultaB)>0){  
        echo "Logar Usuário";       
    } else {    
        echo "Login ou senha inexistente";      
    }
}
    
06.11.2016 / 02:45
1

Resolved In my case I decided to make my system by creating a user table only for login question Users table id name email password

other type tables Distributor table tel address

if ($ user-> select ('email', 'users', 'WHERE email =?', array ($ email)) -> rowCount ()> 0)

print 'email already registered';

    
21.12.2016 / 17:47