<?php

error_reporting(E_ALL);
ini_set('display_errors',1);

require "config.php";

$msg="";

$debug="";

if(isset($_POST['login'])){

$debug.="DB Connected: YES<br>";

$email=
$conn->real_escape_string(
$_POST['email']
);

$password=
$conn->real_escape_string(
$_POST['password']
);


$debug.="Email:
".$email."<br>";


$sql="

SELECT *

FROM users

WHERE

email='$email'

LIMIT 1

";


$q=
$conn->query(
$sql
);


if(!$q){

die(

"MYSQL ERROR:

".$conn->error

);

}


$debug.="Rows:
".$q->num_rows."<br>";



if(
$row=
$q->fetch_assoc()
){


$debug.="User Found<br>";



if(

$password

==

$row['password']

){


$debug.="Password OK<br>";



if(

$row['active']

==1

){


$debug.="Active OK<br>";



$_SESSION['userid']
=
$row['id'];



$_SESSION['firstname']
=
$row['firstname'];



$_SESSION['lastname']
=
$row['lastname'];



$_SESSION['role']
=
$row['role'];



$_SESSION['email']
=
$row['email'];



header(
"Location:dashboard.php"
);

exit;



}else{


$msg=
"User inactive";


$debug.=
"User inactive<br>";



}


}else{


$msg=
"Wrong password";


$debug.=
"Wrong password<br>";



}



}else{


$msg=
"Email not found";


$debug.=
"Email not found<br>";



}

}

?>


<!DOCTYPE html>
<html>

<head>

<meta charset="utf-8">

<meta
name="viewport"
content="width=device-width,initial-scale=1">

<title>

PMS Login

</title>


<style>

body{

margin:0;

height:100vh;

display:flex;

justify-content:center;

align-items:center;

background:

linear-gradient(
180deg,
#05080d,
#0d141b,
#111821
);

font-family:Arial;

}



.card{

width:380px;

padding:40px;

border-radius:24px;

background:

linear-gradient(
135deg,
#1a2630,
#304150,
#1f2b35
);

border:

1px solid rgba(
0,
212,
255,
.2
);

box-shadow:

0 0 35px rgba(
0,
212,
255,
.15
);

}



.logo{

font-size:50px;

text-align:center;

}



.title{

font-size:32px;

font-weight:700;

text-align:center;

color:white;

}



.sub{

text-align:center;

color:#c1cfdb;

margin-bottom:25px;

}



input{

width:100%;

box-sizing:border-box;

padding:18px;

margin-bottom:15px;

background:#101820;

border:none;

border-radius:12px;

color:white;

font-size:16px;

}



button{

width:100%;

padding:18px;

background:

linear-gradient(
90deg,
#009dff,
#00d4ff
);

border:none;

border-radius:12px;

font-size:18px;

font-weight:700;

cursor:pointer;

}



.error{

background:

rgba(
255,
0,
0,
0.1
);

padding:10px;

border-radius:8px;

margin-bottom:10px;

color:#ff8c8c;

}



.debug{

background:black;

color:lime;

padding:10px;

font-size:12px;

border-radius:10px;

margin-bottom:15px;

max-height:120px;

overflow:auto;

}


.footer{

margin-top:20px;

text-align:center;

color:#8ea3b7;

font-size:12px;

}

</style>

</head>



<body>



<div class="card">


<div class="logo">

🩺

</div>


<div class="title">

PMS

</div>


<div class="sub">

Patient Monitoring System

</div>




<?php

if($debug!=""){

echo

"<div class='debug'>

$debug

</div>";

}



if($msg!=""){

echo

"<div class='error'>

$msg

</div>";

}

?>



<form method="post">


<input

type="email"

value="upendra.srikanta@gmail.com" name="email"

placeholder="Email"

required>



<input

value="12" type="password"

name="password"

placeholder="Password"

required>



<button

type="submit"

name="login">

LOGIN

</button>


</form>



<div class="footer">

Industrial PMS Dashboard

</div>



</div>



</body>

</html>