How to redirect to different tables (dynamically) in SQL with selection PHP?

Viewed 25

I'm creating this online examination web page where there is student and lecturers login. I need to redirect to different tables in SQL (student, lecturer) When the user select it in the login menu.(student, lecturer). I have developed this code up to the point where only student login is done. How to change it dynamically with the selection of the user?

SQL table names - students, lecturers Here is my code (up to the point where only student login is done). I'm using email validation here.

<body>
<?php
include("header.php");?>

<br><br><br>

<!-- <img src="C:\Users\DilumPC\img0089.jpg" style="width:100px;height:100px;"> -->
<h2 align="center">Login Form</h2><br><br>
<div class="container">
<form action="" method="post">

  
    <div class="inside">

    <label class="labels" for="usertype">User Type</label>
            <select id="user" name="user">
                <option value="admin">Admin</option>
                <option value="student">Student</option>
                <option value="lecturer">Lecturer</option>
                
            </select> 

            <br><br>
    <label for="email"><b>Email</b></label>
    <input type="text" placeholder="Enter Your Email" name="txtemail" >
    <br>

    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" name="txtpsw" >
        
    <button type="submit" name="btnlogin"  style="border-radius:10px;">Login</button>
    <label>
      <input type="checkbox" checked="checked" name="remember"> Remember me
    </label>
<br><br><br>
    <button type="button" style="border-radius:10px;"class="cancelbtn">Cancel</button>
    <span class="psw">Forgot <a href="#">password?</a></span>
  </div>


</form>
</div>
</body>
</html>
<?php

  include 'db.php';

  session_start();

  if (isset($_POST['btnlogin'])){
    $email = $_POST['txtemail'];
    $psw = $_POST['txtpsw'];
    $user = $_POST ['user' ];

    $sql_login= "SELECT * FROM students WHERE Email='$email' AND Password = '$psw'";
    $status = mysqli_query($con, $sql_login);
    $row_num = mysqli_num_rows ($status);
    if ($row_num==1){
      while ($row= mysqli_fetch_assoc($status)){
        $_SESSION['logged_user_email'] =  $row['Email'];
      }
      header("Location: profile.php");
    }
    else{
      echo "go away";
    }
  }

?>
0 Answers
Related