Registered Users can Save Checklists

Discussion in 'PHP' started by Yukio, Nov 7, 2005.

  1. #1
    Hi guys,

    I'm trying to create a feature where registered users to my site can check "checkboxes" and save it, so next time they log back in, their account remembers which lists are checked or not (I want a big list with checkboxes to tick off tasks they've essentially done etc).

    Would anyone have any links to tutorials to that effect?
     
    Yukio, Nov 7, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Assuming you have a database of all the users of your site you would then need another database with a column for the username and then a column for each checkbox. The value of checkbox1 can either be checked or unchecked.

    You update the database when somebody checks a box and submits the form by only updating the row with the username of whoever sent the form.

    When you log in then the script queries the database and can find out which boxes are listed a checked.

    If this is not clear PM me or post some of your code and I am sure I can help further.
     
    dave487, Nov 8, 2005 IP
  3. Yukio

    Yukio Peon

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm assuming logically, then that the checkboxes have to be unique for each list checked option on the website.

    I'm actually quite new to php... very very very very new and I'm using this as a practice project.

    I have a login system and user system already in place which I used from http://www.evolt.org/article/PHP_Login_System_with_Admin_Features/17/60384/

    From there, I created a page called "avatarlist.php" which would hopefully contain all the options with checkboxe for checking. I'm basing the template for that off useredit.php (from the tutorial) which I assume would be correct.

    I created the table you suggested using the following code:

    DROP TABLE IF EXISTS avatar;

    CREATE TABLE avatar (
    username varchar(30) primary key,
    avatar varchar(32),
    timestamp int(11) unsigned not null
    );

    ===
    Avatar, being the column that will list all the avatars that are checkable.

    What do you think so far? Thanks for your advice ^_^ It's been very helpful.
     
    Yukio, Nov 9, 2005 IP
  4. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am not really too familiar with the script you have used - its seems quite complex to me!

    Basically when somebody is logged in to your site you should be able to output their username to the page eg "You are logged in as J Smith", I am going to assume that the username is stored in the variable $username

    When J Smith fills in and submits a form with a checkbox in it you need to update the avatar database using the following statement (assuming that all the usernames are already entered in the avatar database).

    $result = MYSQL_QUERY("UPDATE avatar SET avatar='$checkbox1' WHERE username='$username'");
    PHP:
    If you want to store more variables like checkbox2 checkbox3 etc you need more colums in the avatar database.
     
    dave487, Nov 9, 2005 IP