I have a problem working out how to return users data when the user logs in.

It needs to work so that when any user logs in only their data is shown.

This is the current table structure;

I have three tables set up;

'Users'
'Profile'
'Linkingtbl'

The 'Users' table holds the following data;
Email (PK)
Password

The 'Profile' table holds the following data;
ProfileID (PK)
Firstname
Lastname
DOB

The 'Linkingtbl' table holds the following data;
ID (PK)
Email (FK)
Password
ProfileID (FK)

I have a login system setup and want to be able to show the users 'ProfileID'.


Thanks

You should have an approx 11 digit user ID # for each registered user. Use that ID as a foreign key any table entry the user owns. Do your join on those foreign keys.

Hello again :)

So you want to show the user's ID from this database, no problem, one question before I start going off on one though:

What user-identifying data do you have available to you on this page that we could use to find other data associated with that user? E.g. a username, first/last name etc?

Hello again :)

So you want to show the user's ID from this database, no problem, one question before I start going off on one though:

What user-identifying data do you have available to you on this page that we could use to find other data associated with that user? E.g. a username, first/last name etc?

I am just showing the ProfileID of the user after they have logged in.

I'm not sure what you mean by that, after the user logs in the only data that I am showinfg at the moment is their ProfileID.

The user must log in using an email address and password.

I am just showing the ProfileID of the user after they have logged in.

I'm not sure what you mean by that, after the user logs in the only data that I am showinfg at the moment is their ProfileID.

The user must log in using an email address and password.

Have you made any further attempt up to now?
As far as I can see, you have all the info you need to make it happen.
Are you still having problems?

Member Avatar for diafol

Oh, so you did need JOIN after all?! Perhaps not.

Your tables look a little confused. Personally I'd do this:

users
=====
id (PK, int, 11)
email (varchar, 75) - serves as username for login
pw (varchar, 32) - this usually contains the hash of the pw (e.g. md5)

profiles
========
pid (PK, int, 11)
id (FK, int, 11)
firstname (varchar, 30)
lastname (varchar,30)
dob (date)

You could probably get away with setting id/pid to less than 11.

If you need the profile data form only storing the user id ($id) - do this:

"SELECT firstname, lastname, dob FROM profiles WHERE id = $id"

You have a choice when a user joins - create a profile in the other table after creating the user.

BUT - because the tables are essentially 1 to 1 - why have separate tables?


users
=====
id (PK, int, 11)
email (varchar, 75) - serves as username for login
pw (varchar, 32) - this usually contains the hash of the pw (e.g. md5)
firstname (varchar, 30)
lastname (varchar,30)
dob (date)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.