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
https://forums.phpfreaks.com/topic/204905-pulling-information-from-session-id/
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?

 

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.

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.