I have created two table name is 'orders' and 'registration' in one database. when I am registering that is working fine and when i am trying to logged in with current registration that is also working fine. but
problem is only that suppose 5 users registered there and they submitted different orders. after loggin while going to see history of orders all users are seeing the same history and all are able to see each others orders in his account after logged in . I am only trying to stop this. so that only logged users can see their own submission only. they should be able to see others user order
As database schema is not available, I'm assuming the structure like this. Change it where you need.
registration table
Id | firstName | lastName | email | ....
Where, Id
is Primary Key
and auto-incremented
orders table
orderId | userID | orderName | ...
Where, orderId
is Primary Key
and auto-incremented
; userID
is Id
of registration table.
So, when you are logged in through registration table. Create one session for Id.
$_Session['user_id'];
(Id
of registration table will be stored here.)
For viewing his/her orders
<?
$userID=$_SESSION['user_id'];
$orderQuery="SELECT * FROM orders WHERE userID=$userID";
.
.//Execute Your query
.
?>
So in orders table you need to add column user id related with foreign key to table users and select orders only for logged/choosed user by id.
For exaple when user is logged you need to get his unique id. And when he wants to see orders query onle results for this particular user. For ex.
set @loggeduser = session_id() from php.
Select * from oreders where userid=@loggeduser;
I can't comment, yet.
Like David said, you could just use something like:
Select * from order
where userid = logedinuserid
but you should also consider to rename the table order. I just asume you have the UserID in the Orders Table...