Page 1 of 1

Retrieving Database Info Based On User logged in

Posted: Sat Sep 11, 2010 1:10 am
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.

Re: Retrieving Database Info Based On User logged in

Posted: Sat Sep 11, 2010 5:50 am
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.