I have this simple MySQL table, which I called data_table:
/--------------+------------------+-------------------\
+ data_id + data_content + addition_content |
+--------------+------------------+-------------------+
+ data_1 + data_content_1 + comment_for_1 |
+ data_2 + data_content_2 + comment_for_2 |
+ data_3 + data_content_3 + comment_for_3 |
+ + + |
+ ... + ... + ... |
+ + + |
+ data_n + data_content_n + comment_for_n |
\--------+-----+------------------+-------------------/
To help users can submit their data to my database, I have created a simple HTML form (with PHP core) for easier data submission.
For getting data from this table (data_table), I have used this query (from my_query.php):
// ...
$var_get = $_GET['url'];
$query_1 = mysql_query("SELECT * FROM `MyDB` WHERE `data_id` = '{$var_get}'");
while ($query_2 = mysql_fetch_array($query_1))
{
echo $query_2['x_2'];
}
// ...
Anyone can see any result (from echo $query_2['x_2'];) when they access my_query.php page with a $_GET[]; value.
Now, I don't want to allow all people can access any data from my website. So, I decide to allow the access-permission to certain users only; and, I have an idea:
- I will create a new MySQL table (
user_table):
/--------------+------------------+-------------------\ + user_id + user_name + user_password | +--------------+------------------+-------------------+ + user_1 + user_name_1 + password_1 | + user_2 + user_name_2 + password_2 | + user_3 + user_name_3 + password_3 | + + + | + ... + ... + ... | + + + | + user_n + user_name_n + password_n | \--------+-----+------------------+-------------------/
- Then, I will add a new data column (
data_owner) to existed table (data_table). Every record (data line) will be have a owner; this owner is the existed user (inuser_table) who submitted their data to my website. - Finally, I will add a new data column (
allowed_user) to existed table (data_table). Every record (data line) will be have some allowed users; these allowed users are existed users (inuser_table) who are allowed to see result (fromecho $query_2['x_2'];). If someone is not an allowed user (from certain record), they won't see the real data.
My idea is not bad?
Sorry, programming is not my job; so, there are some limitations in my programming skills. Can you give me an example, please?
allowed userattrubute set will have access to his data and only his data. No access from a user to data of others?WHEREof your SQL statement, that will be more efficient.