I have a system for registering my system that has two types of users: teacher and student. has a field in the form that is the "user type" of which can be teacher or student. I made a code, but it is very ugly and wanted to help me. It works, but I wanted to know if it has how to do it in a different and simpler way. If you are a student you have to send one page and the teacher sends it to another. follow the code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include_once "conecta.php";
if(isset($_POST)){
$email = $_POST['email'];
$senha = $_POST['senha'];
if(isset($conexao)){
$stmt = mysqli_prepare($conexao,"select email from aluno where email = ? and senha = ?");
mysqli_stmt_bind_param($stmt, "ss", $email, $senha);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $resultado);
mysqli_stmt_fetch($stmt);
if(isset($resultado) > 0){
$_SESSION['login'] = $email;
$_SESSION['tipousuario'] = "aluno";
header("Location: control/home.php");
}else{
echo "Usuário ou senha incorretos";
header("Location: index.php");
}
}
if(isset($conexao)){
$stmt = mysqli_prepare($conexao, "select email from professor where email = ? and senha = ?");
mysqli_stmt_bind_param($stmt, "ss", $email, $senha);
mysqli_execute($stmt);
mysqli_stmt_bind_result($stmt, $resultado);
mysqli_stmt_fetch($stmt);
if(isset($resultado) > 0){
$_SESSION['login'] = $email;
$_SESSION['tipousuario'] = "professor";
header("Location: control/home2.php");
}else{
echo "Usuário ou senha incorretos";
header("Location: index.php");
}
}
}
?>