How to retrieve id from table users in template folder

Discussion in 'Databases' started by ketting00, Jan 31, 2010.

  1. #1
    Hi,

    I've created a user-login-system web site and have a problem to retrieve data in a folder that user is getting there from the other page (not from login form).

    How can I retrieve the user ID from table USERS.

    I use these codes, but it doesn't work.

    $ID = $_GET['ID'];

    $data = mysql_query("SELECT * FROM USERS WHERE ID = '$ID' ") or die(mysql_error());

    $info = mysql_fetch_array( $data );


    Thanks for your help in advance.
     
    ketting00, Jan 31, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,
    try $info['ID']
    btw why you need this from DB when it is WHERE ID = $ID -> searched ID is $_GET['ID'] :)
    Regards,
    Nick
     
    koko5, Feb 1, 2010 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #3
    Thanks for response,

    I'll need this because I want the user to do the update things on their profile page.

    With the codes above I get Notice: unidentified ID.

    It retrieves only information of people on the first row of the USERS table.

    I'm at my wit end to solve this.

    Thanks
     
    ketting00, Feb 1, 2010 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    Hi ketting00,

    Please note that table and field names are case sensitive on *nix systems, so
    TableName != tablename, ID != id and s.o. (if MySQL runs on Windows, they are the same).
    Also you can get first field by $info[0],second $info[1]...:
    
    $info = mysql_fetch_array( $data );
    echo $info[0];
    
    Code (markup):
    Regards,
    Nick
     
    koko5, Feb 1, 2010 IP
  5. blacksheep666

    blacksheep666 Active Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    Put the ID in session or cookie

    like this $_SESSION['id'] OR $_COOKIE[['id']
     
    blacksheep666, Feb 3, 2010 IP
  6. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #6
    This is what I want, big THANKS, not solve all the problems, but at least it works.
     
    ketting00, Feb 14, 2010 IP