Reputation: 151
I am trying to restrict users records display. Basically i am developing a CRM where a user logs in and enters (orders, quotes...) his data and submits to database. So when a user logs in i want to display only those records which he has entered not others data. For this I take user's session
id and stores it infront of his records,
While displaying i am doing like this
"SELECT * FROM orders WHERE user_id='".$_SESIION['userID']."';
But i have to do this 'WHERE' for all display function . Instead of that is there any other way i can do this i mean without repetitive WHERE
statement?
Please suggest
Upvotes: 0
Views: 173
Reputation: 546
Your question: is there any other way i can do this i mean without repetitive WHEREstatement? My answer is: There is no!
Help for prepare: https://www.w3schools.com/php/php_mysql_prepared_statements.asp
The database could be like this, for example:
table users
id_user email password etc.
Table articles
id_article title_article body_article id_user etc
When you query
select * from article where id_users = ?
Use prepere
insert into articles (............, id_user, ....) values (?, ?, ? etc)
All tables, like this one article, can have field id_user, it goes in table with query input ...., by session and prepere protection against SQL injections. And when user select anything, he will have only what he has injected.
Upvotes: 1