tillaart36 Posted September 18, 2006 Share Posted September 18, 2006 Hi you all...I hope someone can help me with this...For school I have a project in PHP, but i'm not very familiar with it. I have a working login system where the user data is inserted in a table called users. This table has an user_id which is auto_increment. After the user has logged in he can make choices (about a house he can design for himself)...How do I keep track of the choices a user makes??? The choices he makes are now inserted in a new table option...in this table is a option_id which is also auto_increment...For now I'm trying to put that option_id also also in the user table. Like that I think I can find a users choices with something like:SELECT option.livingtype FROM option,user WHERE user_id = 1 AND user.option_id = option.option_idThis way i should find the choice of livingtype a user with user_id 1 has made or not??How do i put the option_id (auto_increment) , which is generated by submitting the choices form not only in the option table but also in the users table???Can anyone help me with this?? Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/21141-hold-track-of-a-users-choices/ Share on other sites More sharing options...
HuggieBear Posted September 18, 2006 Share Posted September 18, 2006 When the user logs in, you could add their id into a session variable, maybe called id :) and then when they select their livingtype, you can insert into the table with something like...[code=php:0]sql = "INSERT INTO option (user_id, livingtype) VALUES ('$_SESSION[id']', '$type')";[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21141-hold-track-of-a-users-choices/#findComment-93891 Share on other sites More sharing options...
Barand Posted September 18, 2006 Share Posted September 18, 2006 [quote]How do i put the option_id (auto_increment) , which is generated by submitting the choices form not only in the option table but also in the users table???[/quote]You don't. The users id goes in the option table[pre]user option--------- ---------user_id --+ option_idname | option +-- user_id[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/21141-hold-track-of-a-users-choices/#findComment-93893 Share on other sites More sharing options...
tillaart36 Posted September 18, 2006 Author Share Posted September 18, 2006 Hmm I don't exactly get it...first of all: How do I 'add' their id into a session variable...which command do i use...?? I know I'm very bad with all this stuff but I have to do it for school in a project where a little of php is involved...And when I know how to 'add' the id into a session variable...in which php page must I insert this command? Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/21141-hold-track-of-a-users-choices/#findComment-93899 Share on other sites More sharing options...
HuggieBear Posted September 18, 2006 Share Posted September 18, 2006 A session variable is a way to pass information between pages.An example would be... your user logs in with their username and password, your php code checks their username and password against the values stored in the database and then, assuming they authenticate, returns their nickname.You can then assign this info to a session variable, the code looks something a little like this:[code=php:0]$_SESSION['name'] = "Huggie";[/code]You can then refer to that variable on any of your pages. So you could have this at the top of every page...[code]<?php echo "You are logged in $_SESSION['name']";?>[/code]Which would return [color=green]You are logged in Huggie[/color].This information is active all the time you're still in the same session.There is other information that you need to include, such as session_start() but you can find this out by looking at the relevant pages in the [url=http://uk.php.net/manual/en/ref.session.php]PHP Manual[/url]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21141-hold-track-of-a-users-choices/#findComment-93905 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.