Login with two tables

Asked

Viewed 580 times

0

Gale do not know if I did correctly, I have 2 users, admin and distributor, I created 2 tables, do not know if I did the correct, admin has only id name email and password, already the distributor has id name email password and other more fields.... is it correct to create 2 separate tables, or a single table for the 2 users ? As I made 2 tables, I enclosed in the following: in the login I did with only one table...but I need the 2 users to login..

a CRUD of life is 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;

galera how to log in in this case of 2 tables ?

  • Why didn’t you make a column called type = x? then check what the type is, and log?

2 answers

1

Solved In my case I decided to make my system creating a table of users only for login question Table users id email password

other type tables Distributor table tel address

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

print 'email already registered';

0


You can then do the following procedure:

Check in table A, if e-mail and password exists, if it returns true, check if they are correct, if it returns 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";      
    }
}
  • I’ll try to apply it to my code. Now, give me your suggestion, you find it interesting to create a class relationship like this: 1 - Table A - id name email password Table B - id name email password phone address ... or like this: 2 - Table person id name email password Table admin - permissions Table distributor - address cep telefone ... , that is, in the second the others inherit from the main...?

  • 1

    Thanks for the help, you helped me rethink my logic, I decided to create a single table for users, regardless of who it is or what function it is, I use the USER table only for login. Thanks friend

Browser other questions tagged

You are not signed in. Login or sign up in order to post.