I'm trying to create a multi user login system but when I try to log on it stays on the login page and doesn't move to the next page. What can I do?

index.php

<form method="post" class="form-horizontal">

<div class="form-group">
    <label class="col-sm-3 control-label">Email</label>
    <div class="col-sm-6">
        <input type="text" name="txt_email" class="form-control" placeholder="enter email" />
    </div>
</div>

<div class="form-group">
    <label class="col-sm-3 control-label">Password</label>
    <div class="col-sm-6">
        <input type="password" name="txt_password" class="form-control" placeholder="enter password" />
    </div>
</div>

<div class="form-group">
    <label class="col-sm-3 control-label">Select Type</label>
    <div class=col-sm-3>
        <select class="form-control" name="txt_role">
            <option value="" selected="selected"> - Which one are you </option>
            <option value="admin"> Admin </option>
            <option value="parent"> Parent </option>
            <option value="swimmer"> Swimmer </option>
        </select>
    </div>
</div>

<div class="form-group">
    <div class="col-sm-offset-3 col-sm-9 m-t-15">
        <input type="submit" name="btn_login" class="btn btn-success" value="Login">
    </div>
</div>

<div class="form-group">
    <div class="col-sm-offset col-sm-9 m-t-15">
        You don't have an account at Water Tower 2000 <a href="register.php">
            <p class="text-info">Register Water Tower 2000 Account </p>
        </a>
    </div>
</div>
</form>

index.php PHP Code

<?php
require_once 'connection.php';
session_start ();

if(isset ($_SESSION["admin_login"]))

{
    header ("location:admin/admin_home.php");
}

if(isset ($_SESSION["parent_login"]))

{
    header ("location:parent/parent_home.php");
}

if(isset ($_SESSION["swimmer_login"]))
{
    header ("location:swimmer/swimmer_home.php");
}


if (isset ($_GET['btn_login'])) {

$email = $_GET ["txt_email"];

$password = $_GET ["txt_password"];

$email = $_GET ["txt_role"];

if(empty($email)){

$errorMsg[]="please enter your water tower email";

}

else if(empty($password)){

$errorMsg[]="please enter yout water tower email";
}

else if(empty($role)){

$errorMsg[]="please enter yout water tower email";

}


else if($email AND $password AND $role){

try{

$select_stmt=$db->prepare("SELECT email,password,role FROM masterlogin WHERE email=:uemail

AND password=:upassword AND role=:urole");

$select_stmt->bindParam(":uemail",$email);

$select_stmt->bindParam(":upassword",$password);

$select_stmt->bindParam(":urole",$role);

$select_stmt->excute();

while ($row=$select_stmt->fetch(PDO::FETCH_ASSOC)){

$dbemail =$row["email"];

$dbpassword =$row["password"];

$dbrole =$row["role"];

}
if($email!=null AND $password!=null AND $role!=null){

if($select_stmt->rowCount()>0){

if ($email!==$dbemail AND $password==$dbpassword AND $role==$dbrole){

switch($dbrole) {

case "admin":

$_SESSION ["admin_login"]=$email;
$loginMsg="Admin...Your in Water Tower...";
header("refresh:3;admin/admin_home.php");
break;

case "parent":
$_SESSION["parent_login"]=$email;
$loginMsg="Parent...Welcome To Water Tower...";
header("refresh:3;parent/parent_home.php");
break;

case "swimmer":
$_SESSION ["swimmer_login"]=$email;
$loginMsg="Fellow swimmer...Your in Water Tower...";
header("refresh:3;swimmer/swimmer_home.php");
break;

default:
$errorMsg[]="Sorry but either the email/password/role is wrong";
}

}



else {

$errorMsg="Sorry but either the email/password/role is wrong";
}

}

else {

$errorMsg="Sorry but either the email/password/role is wrong";

}

}

else{

$errorMsg="Sorry but either the email/password/role is wrong";

}

}



catch (PDOException $e){

$e->getMassage();

}

}

else {

$errorMsg="Sorry but either the email/password/role is wrong";

}

}

?>

register.php

<form method ="post" class="form-horizontal">

<div class ="form-group">
<label class = "col-sm-3 control-label">Username</label>  
<div class = "col-sm-6">
<input type = "text" name="txt_username" class="form-control" placeholder = "enter username" /> </div> </div> <div class ="form-group"> <label class = "col-sm-3 control-label">Password</label>
<div class = "col-sm-6">
<input type = "password" name="txt_password" class="form-control" placeholder = "enter password" /> </div> </div> <div class ="form-group"> <label class = "col-sm-3 control-label">Username</label>
<div class = "col-sm-6"> <select class = "" name="txt_role"> <option value = "" selected = "selected"> - select role - </option> <option value = "swimmer">Swimmer</option>
<option value = "parent">Parent</option> </select>
</div> </div> <div class = "form-group"> <div class = "col-sm-offset-3 col-sm-9- m-t-15">
<input type = "submit" name="btn_register" class="btn btn-primary" value = "Register"> </div> </div> <div class = "form-group"> <div class ="col-sm-offset-3 col-sm-9 m-t-15"> You have an account at Water Tower? <a href = "index.php"><p class = "text-info">Login Account </p></a>
</div> </div> </form>

register.php PHP Code

<?php

require_once 'connection.php';

if(isset ($_GET["btn_register"])) 

{

if (isset ($_GET['btn_login'])) {
    $username = $_GET ["txt_username"];
    $email = $_GET ["txt_email"];
    $password = $_GET ["txt_password"];
    $role = $_GET ["txt_role"]


if(empty($username)){
    $errorMsg[]="please enter your usernmae";
}

else if(empty($email)){
    $errorMsg[]="please enter your email";
}

else if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
    $errorMsg[]="please enter a valid email address ";
}

else if(empty($password)){
    $errorMsg[]="please enter password";
}    

else if (strlen ($password) < 6) {
    $errorMsg[]="It needs to be more than 6 characters";
}

else if (empty($role)) < 6) {
    $errorMsg[]="Please select a role";
}


try{
$select_stmt=$db->prepare("SELECT username,email FROM masterlogin WHERE username=:uname OR
email=:uemail");

$select_stmt->bindParam(":uname",$username);
$select_stmt->bindParam(":uemail",$email);
$select_stmt->excute();
$row=$select_stmt->fetch(PDO::FETCH_ASSOC);


if ($row["username"]==$username){
    $errorMsg[]="Sorry but username already exsit";
}

else if ($row["email"]==$email){
    $errorMsg[]="Sorry but email already exsit";
}

else if($isset($errorMsg))

{

$insert_stmt=$db->prepare ("INSERT INTO masterlogin (username,email,password,root) VALUES(:uname,:uemail,:upassword,:urole)");
$insert_stmt->bindParam(":uname",$username);
$insert_stmt->bindParam("uemail",$uemail);
$insert_stmt->bindParam("upassword",$upassword);
$insert_stmt->bindParam("urole",$role);

if($insert_stmt->excute())

{

$registerMsg = "Register Succesfully...Wait Login Page";    
header("refresh:4;index.php"); } } } catch (PDOException $e) { echo $e->getMassage(); } } } ?>

connection.php

<?php

$db_host="localhost";
$db_user="root";
$db_password= "";
$db_name="php_water tower 2000";

try {

$db=new PDO ("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_password);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);

}

catch (PDOEXCEPTION $e) {
    $e->getMessage();
}

?>

logout.php

<?php
session_start();

header ("location:index.php");

session_destroy ();

?>

admin_home.php
<style type = "text/css">

body {
    padding:0;
    margin:0;
    background:
}
    
h1 { font-size:5em; margin:0; padding:0; text-align:center; font-family: 'arial'; position:absolute; top:50%; left:50%; transform: translateX(-50%); } </style> </body> <body> <h1> This is the Admin Page </h1> </body> <?php session_start(); if(isset ($_SESSION["admin_login"])) { header ("location:.../index.php"); } if(isset ($_SESSION["parent_login"])) { header ("location:parent/parent_home.php"); } if(isset ($_SESSION["swimmer_login"])) { header ("location:swimmer/swimmer_home.php"); } if(isset ($_SESSION["admin_login"])) { ?> Welcome, <?php echo $_SESSION ['admin_login']; } ?> <a href = "../logout.php">Logout</a>`

parent_home.php

<style type = "text/css">

body {
    padding:0;
    margin:0;
    background:
}
    
h1 { font-size:5em; margin:0; padding:0; text-align:center; font-family: 'arial'; position:absolute; top:50%; left:50%; transform: translateX(-50%); } </style> </body> <body> <h1> This is the Parent Page </h1> </body> <?php session_start(); if(isset ($_SESSION["parent_login"])) { header ("location:.../index.php"); } if(isset ($_SESSION["admin_login"])) { header ("location:.../admin/admin_home.php"); } if(isset ($_SESSION["swimmer_login"])) { header ("location:.../swimmer/swimmer_home.php"); } if(isset ($_SESSION["parent_login"])) { ?> Welcome, <?php echo $_SESSION ['parent_login']; } ?> <a href = "../logout.php">Logout</a>`

swimmer_home.php

<style type = "text/css">

body {
    padding:0;
    margin:0;
    background:
}
    
h1 { font-size:5em; margin:0; padding:0; text-align:center; font-family: 'arial'; position:absolute; top:50%; left:50%; transform: translateX(-50%); } </style> </body> <body> <h1> This is the Swimmer Page </h1> </body> <?php session_start(); if(isset ($_SESSION["swimmer_login"])) { header ("location:.../index.php"); } if(isset ($_SESSION["admin_login"])) { header ("location:.../admin/admin_home.php"); } if(isset ($_SESSION["parent_login"])) { header ("location:.../parent/parent_home.php"); } if(isset ($_SESSION["swimmer_login"])) { ?> Welcome, <?php echo $_SESSION ['swimmer_login']; } ?> <a href = "../logout.php">Logout</a>
         `

    Sorry couldn't put the code in properly I'm new to the website.

    Brandon3000 changed the title to login system will not work.

      Brandon3000 Sorry couldn't put the code in properly I'm new to the website.

      It's best to use the forum's [code]...[/code] tags for code blocks (rather than what the </> button does). I'll see if I can edit your post accordingly.

        The problem is because you change $_REQUEST, in the original code you had, to $_GET. However, the form(s) are post method forms. The submitted data will be in $_POST, not $_GET.

        I also recommend that you make use of the information in replies you have already gotten on other help forums, so that your code will - be secure (with no exit/die statements after the redirects, all the following code will still run), provide a good User eXperience (UX), be simpler (this will eliminate some of the existing mistakes and make it easier to actually complete this assignment), and through validation and error handing, either work or your code will tell you why it doesn't.

          I might suggest you start by inserting the following at the start of each PHP file for now, to see if it enlightens you (and since for now I don't have time to go through all that code).

          <?php
          ini_set('display_errors', true); // remove or set to false in production
          error_reporting(E_ALL);
          
            Write a Reply...