This topic is locked
[SOLVED]

 Occupying Fields when using $_SESSION["UserID"]

9/7/2012 10:52:31 PM
PHPRunner General questions
S
swanside author

Hello.

I have a query on how to perform this task.

I have two tables,

CREATE TABLE IF NOT EXISTS login (

LoginId int(11) NOT NULL AUTO_INCREMENT,

Name varchar(50) DEFAULT NULL,

Password varchar(50) DEFAULT NULL,

Department varchar(100) DEFAULT NULL,

PRIMARY KEY (LoginId)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;


and

CREATE TABLE IF NOT EXISTS dailylogwork (

DailyLogWorkId int(11) NOT NULL AUTO_INCREMENT,

Department varchar(100) DEFAULT NULL,

Date date NOT NULL,

WorkDone longtext,

Location int(20) NOT NULL,

Equipment int(20) NOT NULL,

User varchar(50) DEFAULT NULL,

PRIMARY KEY (DailyLogWorkId)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;


The user is added to the system by the system admin, and is assigned to a Department, so the login field wil be like this

INSERT INTO login (LoginId, Name, Password, Department) VALUES

(1, 'P.BROWN', 'hollie', 'ELECTRONIC'),

(4, 'A.GREY', '1234', 'ELECTRICAL'),

(5, 'D.BLACK', '1234', 'ELECTRONIC');


When these users go to the dailyworklog and add new, the field User is occupied using $_SESSION["UserID"]

But, I also need the field Department to be automatically occupied to the correct department.
Can anybody please show me how I can do this?

I have tried using the lookup wizard, but it wont work.
Many thanks

Paul

Sergey Kornilov admin 9/8/2012

I believe you can use AfterSuccessfulLogin event to save department value in session variable:

$_SESSION["Department"]=$data['Department'];


Then you can use $_SESSION["Department"] variable as a default value of dailylogwork table Department field or assign value to this field using BeforeAdd event.

S
swanside author 9/9/2012



I believe you can use AfterSuccessfulLogin event to save department value in session variable:

$_SESSION["Department"]=$data['Department'];


Then you can use $_SESSION["Department"] variable as a default value of dailylogwork table Department field or assign value to this field using BeforeAdd event.



Great.

Thanks very much. Worked a treat.