Jump to content

Pulling information from session id


dan_t

Recommended Posts

Hello everyone,

I'm having a little trouble here.

I'm trying to use a session created from log in(the user id)

and take that user id and pull out information from the data base.

 

An example would be:

(this is not the actual code, but I will wrap it anyway)

$_session['username'];
$userId = 'username';

$query ="SELECT * FROM databasetable where userId = (whatever I need to draw out)";
( **Here's where the confusion comes in.** How would I take the $userId variable from the users login and get information such as sex being male or female, and then print userId's of the opposite sex? **)

 

So far I have tried about a hundred different ways with no luck, now I turn to the experts.

So I have totally confused myself - I hope I am asking the question coherently

 

Hopefully you can figure out what I'm looking for.

Link to comment
Share on other sites

Its not really much help not seeing actual code but something like this will likely help you.

 

$query ="SELECT * FROM databasetable where userId = " . $_SESSION['userid'];

 

Not that the $_SESSION array is all caps.

Link to comment
Share on other sites

Before I try and fail again - is there a good way to draw the opposite of a users attribute in a database?

like:

$query = "SELECT databasetable.sex where $userId.sex != $_SESSION['userId'].sex

I realize this would never work, but can you kind of see what I'm going after?

 

Link to comment
Share on other sites

Just trying various pieces of code and throwing each away without troubleshooting why it does not work rarely leads to a quick solution to a problem because -

 

A) You don't learn why any particular method does not work so that you can identify similar code and avoid using methods that don't have a chance of working (I'm going to guess that you have wasted time trying several logically equivalent pieces of code, all with the same result), and

 

B) You could have a systematic problem (with sessions or your database) that until you identify why any particular code does not work, you can try hundreds of things, but the same unidentified underlying problem will prevent all of them from working.

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.