0
I have a registration system of my system that has two types of users: teacher and student. has a field on the form that is the "user type" of which you can be a teacher or student. I made a code, but it’s very ugly, and I wanted you to help me. It works, but I was wondering if you could do it in a different and simpler way. if you are a student you have to send to one page and the teacher sends 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");
}
}
}
?>