zombica86 Posted May 28, 2008 Share Posted May 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/107624-to-insert-session-vriable-value-in-database-table/ Share on other sites More sharing options...
kev wood Posted May 28, 2008 Share Posted May 28, 2008 are you just looking for the code to insert the data into the db table or the code to put the variable in both db tables at once? sorry if i missed something. Link to comment https://forums.phpfreaks.com/topic/107624-to-insert-session-vriable-value-in-database-table/#findComment-551632 Share on other sites More sharing options...
zombica86 Posted May 28, 2008 Author Share Posted May 28, 2008 Yes I am looking for the code that is to be used for inserting the SESSION VARIABLE value actually i dont know how to insert the Session variable value in insert query but onething that it has to be inserted as a foriegn key. Link to comment https://forums.phpfreaks.com/topic/107624-to-insert-session-vriable-value-in-database-table/#findComment-551636 Share on other sites More sharing options...
kev wood Posted May 28, 2008 Share Posted May 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/107624-to-insert-session-vriable-value-in-database-table/#findComment-551675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.