mysql - How to fetch data from two tables based on session variable php? -


actually im trying display data 2 tables on database based on current session, basically, had read many article , forum on how solve problem still facing them till now. data , code did:

<?php include('db.php');  $sql="select* users inner join details on users.id= details.id limit 1 users.id ='$loggedin_id' " ;  $result=mysqli_query($db,$sql); if (!$result) { printf("error: %s\n", mysqli_error($db)); exit(); } ?>       

so here, got error: "error: have error in sql syntax; check manual corresponds mariadb server version right syntax use near 'where users.id = '16'' @ line 3". if use query:

 $sql="select* users inner join details on users.id= details.id" 

it display data in database, need data current session.

here session.php file:

<?php  include('db.php'); session_start(); $user_check=$_session['sess_username']; $ses_sql=mysqli_query($db,"select username,id users username='$user_check' "); $row=mysqli_fetch_array($ses_sql,mysqli_assoc); $loggedin_session=$row['username']; $loggedin_id=$row['id']; $role = $_session['sess_userrole']; if(!isset($loggedin_session) && $role!="user"){   header('location: index.php?err=2'); } ?> 

this tables detail: table users table details

hope can me, im new sql , php. tq

change query that.

$sql="select* users inner join details on users.id= details.id users.id ='$loggedin_id' limit 1" ; 

Comments

Popular posts from this blog

python - PyInstaller UAC not working in onefile mode -

php - Need to store a large amount of data in session with CI 3 but on storing large data in session it is itself destorying automatically -

ios - Pass NSDictionary from Javascript to Objective-c in JavascriptCore -