...

View Full Version : bringin up users data



runnerjp
01-24-2008, 09:55 PM
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

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?

awatson
01-24-2008, 10:38 PM
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.

oesxyl
01-24-2008, 10:39 PM
- missing a '"" at the end of:



$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

runnerjp
01-25-2008, 01:22 AM
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

runnerjp
01-25-2008, 01:25 AM
$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

oesxyl
01-25-2008, 01:54 AM
$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

runnerjp
01-25-2008, 01:42 PM
ahh sorry miss read your questions


i do to add a users data i use


$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

oesxyl
01-25-2008, 08:41 PM
ahh sorry miss read your questions

i do to add a users data i use


$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

runnerjp
01-25-2008, 08:56 PM
ahhh think we might be crossing wires :D

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

oesxyl
01-25-2008, 09:27 PM
ahhh think we might be crossing wires :D

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum