Jump to content

MYSQL Query Question with Sessions


MishieMoo

Recommended Posts

Okay so I have a memberlist on my site.  I've been able to display all the information correctly, but I've run into a little snag.  The part of my code that I'm having a problem with is this

$uid = mysql_query("SELECT * FROM users WHERE id = '$id'"); //Searches the database for the user with the id specified in the url
if (mysql_num_rows($uid) !=0) {$u = mysql_fetch_array($uid);
	extract($u);
	echo '<strong>Viewing '.$username.'´s Profile </strong><br />';
	echo 'Nickname: '.$name.'<br />';
    echo 'Email: '.$email.'<br> 
            Last Login: '.$lastlogin.'<br> 
            Joined: '.$signup.'<br>.'; 


	$back = $id - 1; //The id in the url minus 1

	$forward = $id + 1; //The id in the url plus 1

	print '<a href="/members.php?id=$back">Last:</a>'; //A link to the previous profile

	print '<a href="/members.php?id=$forward">Next</a>';//A link to the next profile


	}

If you notice I have a mysql_query that's selecting * from my user table.  When this code is on the profile, and I visit another person's profile from my own, I become logged in as them with everything changing except the user id.  But when I change it so that I'm selecting just the information from the table that's being displayed (in this case username, name, email, last login, and signup date) that doesn't happen.

 

My question is, how does selecting all from the database change the variables that I'm logged in with. I use sessions to establish username and rank, which are the two major things changing right now.  How or why are those two variables being changed?

 

I know I can do it the other way, but after the profile's are finished they'll have quite a bit of information on them and I'd like to use the * instead of listing out every column of the table.  If someone could give me a clue it would be lovely xD

Link to comment
Share on other sites

Register_globals are off.  I'm using $_SESSION globals.  And I'm not exactly sure what you mean by the names.  I've tried this using $u[username] instead of $username and it's still the same output.  If you mean that $u is the same variable that I'm using when I register the $_SESSION then no.  That's $user_info.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.