Jump to content

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!!
Link to comment
https://forums.phpfreaks.com/topic/21141-hold-track-of-a-users-choices/
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
[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]
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!!
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.