I have created a Login where the ID is stored in a $_SESSION['login_user'].
After authentication, the user is redirected to his home page. I wanna get the value from the session and use it in a query to retrieve all attributes from the database, corresponding with this userID. This is the code I have tried.
session_start();
..........
..........
..........
$uid= $_SESSION['login_user'];
$result = mysqli_query($db,"SELECT * FROM users UID ='".$uid."'");
It is supposed to get all the values stored in the database of table 'users', but the problem is, sometimes it works, sometimes it doesn't. Most of the time, it doesn't work. I would appreciate some help with this one
I have also checked whether the Session is empty or not , before going through this step.
This is the part of login when setting the Session:
$result=mysqli_query($db,"SELECT uid FROM users WHERE username='$username' and
password='$password'");
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
$_SESSION['login_user']=$row['uid'];
Have you tried using correct SQL syntax like SELECT * FROM {table} WHERE something=someval? Like:
$result = mysqli_query($db,"SELECT * FROM users WHERE UID ='".$uid."'");