Jump to content

To insert Session Vriable Value in Database Table


zombica86

Recommended Posts

Hello I am new to PHP and dont know well about it. I am getting some problem in inserting $_SESSION variable value in database. I have a table called staff_users from that table i have to get a field called SID(StaffId) which i have done and it's working  by this:::

 

$staff_id=$_SESSION["SID"];

echo $staff_id;

 

but the problem is that i want to insert this SESSION VARIABLE Value in another table called ORDERS which contain a field called staff_member_id (FK). How can I insert this session variable value in another table.

 

Plz give me the solution of that and please try to be in simple way.THANX

when you set you table you could have set foreign key here by doing this

 

CREATE TABLE ORDERS
(Order_ID integer,
Order_Date date,
Customer_SID integer,
Amount double,
Primary Key (Order_ID),
Foreign Key (Customer_SID) references CUSTOMER(SID));

 

or if you already have set the table up then you can write the code like this

 

ALTER TABLE ORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);

 

to insert the data into the table the table then you would need this code

 

$sql="INSERT INTO staff_users (ORDERS) VALUES ('$staff_id')";
			$query = mysql_query($sql);

 

the insert into line of code will put the value held by $staff_id into the column named ORDERS in the table staff_users

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.