Jump to content

Archived

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

tillaart36

Hold track of a users choices

Recommended Posts

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_id

This 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!!

Share this post


Link to post
Share on other sites
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]

Regards
Huggie

Share this post


Link to post
Share on other sites
[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_id
name      |    option
          +--  user_id
[/pre]

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites
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]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.