Jump to content

Get user id from database


friiks

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.