I have these two files and I need to solve the problem that I need the user data in the role column to be taken when logging in. I have written it so that the data can be extracted from the database, but it does not work for me that it is “forwarded” from process.php
to admin.php
. Please don’t know what the error is that the admin.php
file doesn’t want to load $ _SESSION['Role']
from process.php
? Thanks to everyone for helping and here is the code:
process.php
<?php
require_once('connect.php');
session_start();
if(isset($_POST['Login']))
{
if(empty($_POST['Username']) || empty($_POST['Password']))
{
header("location:index.php?Empty= Please Fill in the Blanks");
}
else
{
$query="select * from role_test where Username='".$_POST['Username']."' and Password='".md5($_POST['Password'])."'";
$result=mysqli_query($con,$query);
if(mysqli_fetch_assoc($result))
{
$_SESSION['User']=$_POST['Username'];
while($row = mysqli_fetch_array($result) ){
$_SESSION['Role']=$row['role'];
}
header("location:admin.php");
}
else
{
header("location:index.php?Invalid= Please Enter Correct User Name and Password ");
}
}
}
else
{
echo 'Not Working Now Guys';
}
?>
admin.php
<?php
session_start();
if(!(isset($_SESSION['User'])))
{
header("Location: index.php");
exit(0);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Role</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<?php
$_SESSION['Role']=$role;
echo $role;
?>
</body>
</html>