Click here to Skip to main content
15,748,615 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
Hello so i have created this web application for a master degree grade but i need your help to do something! So this web app is all about learning. There are teachers and students. I have created the database to store the users and i have created 2 tables ('teachers' and 'students'). So the registration form is done and works.I can register to both tables. I have only 1 login page(form) where i can login both as a teacher and student but what I want is to be able to define that if a user is a 'teacher' to have access to the uploads for different subjects.Basically i need the code to check the teachers' table and if the user exists redirect him to the teacher homepage.!
My actual login page code is this!:
Any help would be very appreciated .
I am using Xampp!

<?php
session_start();
require_once("class.user.php");
$login = new USER();

if($login->is_loggedin()!="")
{
	$login->redirect('home.php');
}
if(isset($_POST['btn-login']))
{
	$uname = strip_tags($_POST['txt_uname_email']);
	$umail = strip_tags($_POST['txt_uname_email']);
	$upass = strip_tags($_POST['txt_password']);
		
	if($login->doLogin($uname,$umail,$upass))
	{
		$login->redirect('home.php');
	}
	else
	{
		$error = "Emaili ose fjalëkalimi ishin gabim. Ju lutem provoni përsëri";
	}	

    if($login->doLogin_teacher($uname,$umail,$upass))
    {
        $login->redirect('home.php');
    }
    else
    {
        $error = "Emaili ose fjalëkalimi ishin gabim. Ju lutem provoni përsëri";
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IB-Learning</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="style.css" type="text/css"  />
</head>
<body>

<div class="signin-form">

	<div class="container">
     
        
       <form class="form-signin" method="post" id="login-form">
      
        <h2 class="form-signin-heading">Kyquni tani!</h2><hr />
        
        <div id="error">
        <?php
			if(isset($error))
			{
				?>
                <div class="alert alert-danger">
                   class="glyphicon glyphicon-warning-sign">   <?php echo $error; ?> !
                </div>
                <?php
			}
		?>
        </div>
        
        <div class="form-group">
        <input type="text" class="form-control" name="txt_uname_email" placeholder="Username ose Emaili juaj" required />
        <span id="check-e"></span>
        </div>
        
        <div class="form-group">
        <input type="password" class="form-control" name="txt_password" placeholder="Fjalëkalimi juaj" />
        </div>
       
     	<hr />
        
        <div class="form-group">
            <button type="submit" name="btn-login" class="btn btn-default">
                	^__i class="glyphicon glyphicon-log-in">   Kyquni
            </button>
        </div>  
      	<br />
            <label>Nuk jeni regjistruar ende? <a href="sign-up_student.php">Regjistrohuni këtu</a></label>
      </form>

    </div>
    
</div>

</body>
</html>


What I have tried:

I haven't tried anything because i dont know how!!
Please help...
Posted
Updated 1-Jan-17 17:22pm

1 solution

The idea is like this:
1. In the table where user data is stored, add a field say role, to indicate a registered user's role as teacher or student, this should be done by an administrator of the website.
2. When a user logs in successfully, direct him to the appropriate home page based on his role.
3. Not to forget, on each page, you have to check that it is only accessible by a user with the correct role.
I will not go into the nitty gritty of database design and coding, try it yourself, if you encounter problems, you may seek further advice here.
Having said that, this tutorial[^] should help you to kick start.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900