this is my first code I wrote in php I follow tutorials.. I want this code to select all fields in privilege table and check the id of user who logged in and his access level but the access level doesn't change with every user logged in
I use relation between two tables they are: privilege table
+----------------------------------+
| AccessLevel | logi_id | pre_id |
|----------------------------------|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 4 | 2 | 4 |
+----------------------------------+
and this is login_pre table:
+----------------------------------+
| username| userpass | login_id |
|----------------------------------|
| a | 123 | 1 |
| a | 123 | 1 |
| b | 1234 | 2 |
+----------------------------------+
this is access page :
<?php
ob_start();
session_start();
include 'C:\xampp\htdocs\database\agtdatabase\agt_site\connection\connect.php';
$query ="SELECT * FROM privilege " ;
$result = mysqli_query($link,$query) or die('');
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$access = $row['AccessLevel'];
echo $access; //result 124 in database
}
if(isset($_SESSION['sessionloginid']))// point to id of user logged in
{
echo $_SESSION['sessionaccess']=$access;// "that is print wrong result " access level doesn't change based on user logged in
echo $_SESSION['sessionloginid'];
}
ob_end_flush();
?>
and this is login page:
$username = $_POST['username'];
$userpass = $_POST['userpass'];
$loginid = $_POST['login_id'];
if($username && $userpass )
{
$finduser = mysqli_query($link,"SELECT * FROM login_pre WHERE username = '".$username."' AND userpass = '".$userpass."'") or die("error");
if(mysqli_num_rows($finduser) !=0)
{
while($row = mysqli_fetch_array($finduser))
{$uname = $row['username'];
$upass = $row['userpass'];
$uloginid = $row['login_id'];
}
}
if($username == $uname && $userpass == $upass )
{
$_SESSION['sessionname'] =$uname;
$_SESSION['sessionpass'] =$upass;
$_SESSION['sessionloginid'] =$uloginid;
echo $_SESSION['sessionloginid'];//result 124 of users
}else header("location: login2.php");
ob_end_flush();