php - How to get user id in session? -


kinda noob problem i'm working on 2 hours , can't solve

i have login system works fine (thanks tutorials), i'd save id in session when user's logging

this login.php:

<?php session_start(); require_once 'config.php'; if(isset($_post['btn-login'])){  $uname = $_post['txt_uname_email'];  $umail = $_post['txt_uname_email'];  $upass = $_post['txt_password'];  $sth = $bdd->prepare("select user_id users user_name=$uname");  $sth->execute();  $result = $sth->fetch(pdo::fetch_assoc);  $uid = $result;   if($user->login($uname,$umail,$upass)){             $_session['user_name'] = $uname;             $_session['user_mail'] = $umail;             $_session['user_session'] = $userrow['user_id'];             $_session['user_id'] = $uid;             $uname = $_post['txt_uname_email'];               $umail = $_post['txt_uname_email'];             $upass = $_post['txt_password'];             var_dump($_session['user_name']);             $user->redirect('index.php');          } else {             $error = "wrong details !";          }     } ?> 

the var_dump of $_session['user_name'] works, when var_dump($_session['user_id']);, shows "null"

i don't know @ what's problem .. got solution ?

thanks

it's not answer pointing in right direction , highlighting errors have in code,

<?php session_start(); require_once 'config.php'; if(isset($_post['btn-login'])){  $uname = $_post['txt_uname_email']; //here $_post same  $umail = $_post['txt_uname_email']; //here $_post same  $upass = $_post['txt_password'];  $sth = $bdd->prepare("select user_id users user_name=$uname");  $sth->execute();  $result = $sth->fetch(pdo::fetch_assoc);  $result = $_session['user_id']; // this,?  $uid = $result; // this?   //you not fetching data database against select query   if($user->login($uname,$umail,$upass)){     //here setting post variables session, thats why getting $_session['user_name'] on var_dump             $_session['user_name'] = $uname;             $_session['user_mail'] = $umail;             $_session['user_session'] = $userrow['user_id']; //where coming             $_session['user_id'] = $uid; //it can't eqaul $result;             $uname = $_post['txt_uname_email']; // mistake             $umail = $_post['txt_uname_email']; // mistake             $upass = $_post['txt_password']; // mistake             var_dump($_session['user_name']);             $user->redirect('index.php');          } else {             $error = "wrong details !";          }     } ?> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -