Jump to content


Photo

Hold track of a users choices


  • Please log in to reply
4 replies to this topic

#1 tillaart36

tillaart36
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 18 September 2006 - 11:27 AM

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

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 September 2006 - 11:57 AM

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

sql = "INSERT INTO option (user_id, livingtype) VALUES ('$_SESSION[id']', '$type')";

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 18 September 2006 - 11:58 AM

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???


You don't. The users id goes in the option table

[pre]
user            option
---------      ---------
user_id  --+    option_id
name      |    option
          +--  user_id
[/pre]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 tillaart36

tillaart36
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 18 September 2006 - 12:18 PM

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

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 September 2006 - 12:45 PM

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:

$_SESSION['name'] = "Huggie";

You can then refer to that variable on any of your pages.  So you could have this at the top of every page...

<?php
   echo "You are logged in $_SESSION['name']";
?>

Which would return You are logged in Huggie.

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 PHP Manual

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users