Retrieving Database Info Based On User logged in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saran.tvmalai
Forum Newbie
Posts: 4
Joined: Sat Aug 28, 2010 4:07 am

Retrieving Database Info Based On User logged in

Post by saran.tvmalai »

I have two tables.

Table Name:Users

Fields:

User_name
user_email
user_level
pwd


2.Reference

Fields:

refid
username
origin
destination

user_name in the users table and the username field in reference fields are common fields.



There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be
provided with an refid

Steps:

1.User needs to log in with a valid user id and pwd
2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement.
3.Now User is able to view all the details for any refid
3.Up to this we have completed.

Query:

Now we need to retrieve the details based on the user logged in.

For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement
user 'USER B' has been provided with the referenceid '2468' during the time of order placement

When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him.
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Retrieving Database Info Based On User logged in

Post by oscardog »

It sounds a litte overcomplicated but by my understanding this should do the trick.

Code: Select all

$query = mysql_query("SELECT * FROM reference WHERE username = '".$logged_in_user."'"); 
Obviously you need to set $logged_in_user as the username of the person who is logged in.
Post Reply