friiks Posted November 19, 2006 Share Posted November 19, 2006 Hi!I'm making a site which u can register in, upload stuff and get dynamic image which tells how many downloads there are. The files you upload are uploaded in users own directory and the data about the file is stored in database.My problem is that I have always used [b]while[/b] loop to get data from database and I don't know how to get only one result which should be the users id.I did it with while loop like this [code] $result = mysql_query("select * from users");while($r=mysql_fetch_array($result)){$id=$r["id"];session_register('id');$_SESSION['id'] = $id;} session_register('username'); $_SESSION['username'] = $username; session_register('special_user'); $_SESSION['user_level'] = $user_level;[/code]it registers the id in a session...but all the users get the same id number displayed now...If this doesn't explain all I can send the full code in a pm as I don't want to post it here... Link to comment https://forums.phpfreaks.com/topic/27765-get-user-id-from-database/ Share on other sites More sharing options...
trq Posted November 19, 2006 Share Posted November 19, 2006 Your problem isn't the loop, though that isn't needed. Your problem is your query.[code]select * from users[/code]You are selecting all users. What are you trying to do exactly? Log a user in? You need a way to identify a user for a login, this is usually supplied as a username / password combination from the user.Also, the session_register() function has [b]long[/b] been depricated. I don't know where your reading this tutorial, but its well out of date. Link to comment https://forums.phpfreaks.com/topic/27765-get-user-id-from-database/#findComment-127027 Share on other sites More sharing options...
friiks Posted November 19, 2006 Author Share Posted November 19, 2006 Thanks for the info :)'users' is the table where user info is stored..And I'm trying to get the id of user which is logged in.. Link to comment https://forums.phpfreaks.com/topic/27765-get-user-id-from-database/#findComment-127032 Share on other sites More sharing options...
trq Posted November 19, 2006 Share Posted November 19, 2006 Are they already logged in, or are you trying to log them in? If there already logged in then you should store there id in a session variable when you log them in, otherwise, there must be some other unique value stored in a session to identify them. Link to comment https://forums.phpfreaks.com/topic/27765-get-user-id-from-database/#findComment-127061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.