Forum Moderators: coopster

Message Too Old, No Replies

Restricting user query/search access issue.

login user restriction to company data results.

         

aftershock2020

7:34 am on Dec 17, 2007 (gmt 0)

10+ Year Member



Hey,

I am having an issue of figuring out how to restrict a search page that is based on php using mysql queries revealing the results to the client/user based on the jobs/projects being handled by the company.

The client/user is a member of the client/company, as the contact or representative. With that, the connection in the access to content is based from the association of the username_id of the user and the company_id of the company that he represents being how he gets to see the information of the project status generated by the database.

Can anyone help me with a quick code resolution for associating this?

At present, I have two tables for this.

Table 1 is the production information table.

Table 2 is the user/login table.

The joining information is the Company_ID that is represented on both.

I want to have the data from the database that the user is able to access and read to be restricted to the company_id associated via the query and query results.

How would I be able to go about doing this? I know it is as simple. I'm just not seeing it.

cameraman

8:18 am on Dec 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably something like:
SELECT production.* FROM production,user WHERE ((username='$user') AND (user.company_id=production.company_id))

aftershock2020

8:45 am on Dec 17, 2007 (gmt 0)

10+ Year Member



Thanks for the response. Now, how would I go about listing a select for individual column values based on the same query?

I'm using php/mysql and with the mysql flexability to add as many column values to a single table, I am wanting to take advantage of the and filter the viewing with this method for those that won't have access to EVERYTHING on a given row.

Should work as a simple query selecting set values, right?

cameraman

9:13 am on Dec 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You replace production.* with a comma delimited list of the field names (columns) you want to retrieve. If the field names are unique to the production table then you can use just the field names themselves. If the same field name exists in both tables, precede the field name with production. (the table name and a period).

There's some good reading in this forum's library - this thread has links to other threads:
Basics of extracting data from MySQL using PHP [webmasterworld.com]

aftershock2020

9:50 am on Dec 17, 2007 (gmt 0)

10+ Year Member



Excellent. Thanks.

one more if you don't mind. Any good coding options for updating from a php form to mysql database to replace/update existing row values?

I have a massive form for a client and the form works incredibly well. I just don't know a good way of allowing them to update it via an "update" button next to the submit and have it work properly.

any suggestions here would be highly appreciated.

Thanks again for your help.

cameraman

10:42 am on Dec 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I understand what you're asking. If you mean 'as opposed to doing an insert' then I find it easier to figure it out programmatically than confuse the user with which button to push. If you've retrieved the record from the table, then you can include the record id as a hidden field on the form. If it's a new record, set the id to an invalid value (like to zero or -1 if it's numeric or a blank value if it's alpha) . When the form is submitted, look at the record id - if it's valid do an update and if it's invalid do an insert.

aftershock2020

12:32 pm on Dec 18, 2007 (gmt 0)

10+ Year Member



Was asking " HOW " to do an update for a form. I don't have the first clue as to how to go about it. I've built plenty of forms and have always used my own access to the database to update and change directly. Now, I'm working client-side on the current application and need to know how to do so.