Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts

    bringin up users data

    thankyou for looking at my problem

    i have code set up so i can deleted users data edit it see it ect... im having trouble showing only the users data that is logged in
    i uses the session $id = $_SESSION['user_id']; to get the users id who is logged in... it should be easy but i seem to be having a mind blank out but with the code provided here

    Code:

    PHP Code:
    <?php

    include("connect.php");
    $query "SELECT * FROM users WHERE ????;
    $result=mysql_query($query);
    $num = mysql_num_rows ($result);
    mysql_close();

    if ($num > 0 ) {
    $i=0;
    while ($i < $num) {
    $first_name = mysql_result($result,$i,"
    first_name");
    $events = mysql_result($result,$i,"
    events");
    $about_me = mysql_result($result,$i,"
    about_me");
    $dob = mysql_result($result,$i,"
    dob");
    $id = mysql_result($result,$i,"
    ID");

    echo "
    <b>First Name:</b$first_name<br>";
    echo "
    <b>Events:</b$events<br>";
    echo "
    <b>About me:</b$about_me<br>";
    echo "
    <b>DOB:</b$dob<br>";
    echo "
    <a href="update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";
    echo 
    "<br><br>";

    ++
    $i; } } else { echo "The database is empty"; }?>

    to just show the users logged on currently data?


    at the moment i use $id = $_SESSION['user_id']; to get users id currently logged in... any way i can inplement thios into the code so i can gt that users information and is it safe?

  • #2
    New Coder
    Join Date
    Jan 2008
    Posts
    63
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm not sure I understand exactly what you're looking for...

    It sounds like perhaps you need a page to list all users - you'll need to do a "select *" from your users table, and then for each record returned output the users's name as a link, with the link including the record's id as a parameter so you can click the link to go to that user's record.
    Web hosting by coders, for coders: php hosting - Magento eCommerce hosting - perl hosting - check us out!

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    - missing a '"" at the end of:

    PHP Code:
    $query "SELECT * FROM users WHERE ????"
    - do you update the database, table users, with each user what is loged in?
    - how did you store in users table, the info that a user is logout?

    best regards

  • #4
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    what i want to do is select the data from the user currently logged into the page... so i would like to see the profile of user runnerjp ect

  • #5
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    $id = $_SESSION['user_id']; gets the current logged in datas id numner so e.g

    runnerjp has id 1
    awatson has id 2
    oexsyl has id id

    i want to look at oexsyl data so i would use $id = $_SESSION['user_id']; to find oexsyl id from his logged in status and its 3.... so i will get all data under 3

    so how i add it into my data

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by runnerjp View Post
    $id = $_SESSION['user_id']; gets the current logged in datas id numner so e.g

    runnerjp has id 1
    awatson has id 2
    oexsyl has id id

    i want to look at oexsyl data so i would use $id = $_SESSION['user_id']; to find oexsyl id from his logged in status and its 3.... so i will get all data under 3

    so how i add it into my data
    I understand what you want to do. My questions are:
    - when the user oesxyl is logged in do you have a mysql query which add his $id and other info about him to some table?
    - when the user oesxyl is logged out, do you have a mysql query which update a table with some information that oesxyl is logged out?

    best regards

  • #7
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ahh sorry miss read your questions


    i do to add a users data i use
    PHP Code:
    $id $_POST['id'];
    $first_name $_POST['first_name'];
    $events $_POST['events'];
    $about_me $_POST['about_me'];
    $dob $_POST['dob'];

    $update "UPDATE users SET first_name = '$first_name', events = '$events', about_me = '$about_me', dob = '$dob' WHERE id='$id' ";
    $rsUpdate mysql_query($update);
    if (
    $rsUpdate)
    {
    echo 
    "Update successful.";
    mysql_close();
    ?> 

    2.

    i havent got anything that tells a users that "oesxyl" is logged out no... but i use a session to get the users logged in id

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by runnerjp View Post
    ahh sorry miss read your questions

    i do to add a users data i use
    PHP Code:
    $id $_POST['id'];
    $first_name $_POST['first_name'];
    $events $_POST['events'];
    $about_me $_POST['about_me'];
    $dob $_POST['dob'];

    $update "UPDATE users SET first_name = '$first_name', events = '$events', about_me = '$about_me', dob = '$dob' WHERE id='$id' ";
    $rsUpdate mysql_query($update);
    if (
    $rsUpdate)
    {
    echo 
    "Update successful.";
    mysql_close();
    ?> 
    your mysql update, replace the first_name, events, about_me and dob with the values from a form, I guess, for a user who's id is $_POST['id']
    That means that if awatson is loged in and have id 2, and oesxyl will login with same id = 2, awatson will be replaced with oesxyl.
    That is what you want?

    Do you have probably some code to register new users, isn't it?

    i havent got anything that tells a users that "oesxyl" is logged out no... but i use a session to get the users logged in id
    How do you get the users logged in id? If you want to use $_SESSION['user_id'] you can't because his current value is yours not oesxyl or others user. The only way is to read id from your table users but this is messed by the fact that the user could be loged out and you have no way to find this without a logout script.

    best regards
    Last edited by oesxyl; 01-25-2008 at 07:44 PM.

  • #9
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ahhh think we might be crossing wires

    all i want to do is update my own profile
    and for oesxyl to update oesxyl's own profile and awatson to update awsones own profile but how can i make it so awatson's profile comes up when he wants to edit it or oesxyl's profile from the same page e.g www.mywebsite.com/editprofile

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by runnerjp View Post
    ahhh think we might be crossing wires

    all i want to do is update my own profile
    and for oesxyl to update oesxyl's own profile and awatson to update awsones own profile but how can i make it so awatson's profile comes up when he wants to edit it or oesxyl's profile from the same page e.g www.mywebsite.com/editprofile
    This is the way I see:

    On login you must use user name or/and other information to identify the user, so I must write in a form "oesxyl" and my password to be logged in.
    You must use the user name and password to:
    - check if the user have access rights
    - retrive from mysql a id, oesxyl id in this case
    - you can create a uniq session id for oesxyl and pass from page to page
    until is logged out and store into a table along with user id

    on each page you check if the session id passed from previous page exists in your table

    when oesxyl want to update his profile or any page, you use session id passed from previous page to get his id, and do update,

    when oesxyl log out, delete the session id and remove the row from your table.

    best regards
    Last edited by oesxyl; 01-25-2008 at 08:30 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •