This topic is locked
[SOLVED]

 Passing Session Variable in WHERE of SQL QUERY

1/16/2020 4:34:50 PM
PHPRunner General questions
S
sharizkhan author

Hi ALL

Scenario is
I have created employees table and set it to store login and passwords have emp_id as primary key

  1. will there be _SESSION['emp_id'] available automatically? or it will be required to initialized in after successful login event
  2. A field shop_keepers is a drop down and in its WHERE of that drop down i have entered the following

rpDayofWeek = WEEKDAY(CURDATE()) AND employeeId = '" . $_SESSION['emp_Id'] . "'


but unable to get the value of emp_id
Please guide what i am missing?
Thanks

K
keithh0427 1/16/2020

You will need to declare the Session variable after a successful login. There are some session login variables that you could use as well that keeps the login name.
Also, you have 'emp_Id' and 'emp_id'. Those are two separate variables. Variables are case sensitive.

A
acpan 1/16/2020

eg: use Security API to get the data and store in session var.
After login successful event:



// Get the current logged in user data from the user table

$userData = Security::currentUserData();

$_SESSION['emp_id'] = $userData["emp_id"];


As what keithh0427 mentioned, var are case sensitive, for beginners, it is better to use all lowercase for var and table field names to save time on debugging error due to inconsistent use of upper and lower cases.
ACP



You will need to declare the Session variable after a successful login. There are some session login variables that you could use as well that keeps the login name.
Also, you have 'emp_Id' and 'emp_id'. Those are two separate variables. Variables are case sensitive.

S
sharizkhan author 1/17/2020

Thanks for your reply, infact problem is resolved by

employeeId = ':user.empId'


Regards