Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
03-16-2010, 03:35 PM #1
- Join Date
- Mar 2010
- Thanked 0 Times in 0 Posts
help with concurrent users in php/mysql site
Please forgive me I am very new to php and I have recently set up a simple admin area for a pet shop to update items in their oscommerce catalog.
the oscommerce admin area was way to scary and complex for the staff at the stores so I volunteered to make a simple admin area that they could add livestock such as puppies into.
there are 6 stores that each want to regulary add/remove and edit their livestock in the site.
I used dreamweaver to create a very simple admin area for them and I need help with 2 issues actually
The admin area simply uses a set of forms in 4 steps to enter the livestock data into 3 seperate tables. (final step is to view and edit)
My first problem is how I can ensure that if more than 1 user logs into this admin area there will not be issues with concurrency so I need a way to either lock out other users when the admin area is in use.
implement something that allows multiple users to add/remove and edit entries without interfering with each other or corupting the data if thats possible.
on the 3rd step of entering in for example "a puppy", I have a textarea which is for the "product_description" which has the init value prefilled with a html template giving puppy and store information.
what I would like to do is make it so that when a "particular user" is on that step the prefilled information in that textarea has "that stores" details so they only have to do minor editing of the puppies details and not have to worry about their store information.
If a different user from a different store is logged in then that textarea will have their particular stores details prefilled depending on which user is entering the data.
so my 2 questions are:
1) how to ensure that no database issues occur if more than one person is trying to enter data at the same time
2) have a particular text area in step 3 of the forms populated automatically with a logged in stores particulars
Any help would be greatly apreciated.
03-16-2010, 03:58 PM #2
- Join Date
- Nov 2007
- Thanked 330 Times in 326 Posts
1) Describe a situation in which you think there would be a problem with data inconsistency. I suspect that it won't happen for normal usage. However, a robust application will handle all possible issues.
2) Since the admin users are logged in,. you have their user IDs throughout the data entry process. Simply find their associated store ID and data before the form is rendered and use it to pre-fill the form inputs.
Are you a Help Vampire?
03-16-2010, 03:59 PM #3
- Join Date
- Dec 2005
- Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
- Thanked 637 Times in 625 Posts
You're working with an architecture that does not lend itself well to exclusive locking. Browsers and HTTP are stateless, meaning there's no real communication back and forth happening; it's more of a request-fulfill-done situation. Because of this, I think you would cause more headaches than you would prevent if you tried to implement database locks.
Furthermore, why do you feel that you need locking? What's the problem with multiple people using the admin area at once? While a user is sitting on a page filling out a form, nothing is happening in the database. The only risk you have is if two users edit the same row at once; the last one to hit "update" is whose changes will stick, but they won't corrupt anything.
Regarding the default values being specific to which store is logged in, I'd just create a table keyed on store ID and put the defaults in this table. When a page loads, grab the info off this table where the store ID matches the user's store ID.
03-16-2010, 04:03 PM #4
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,660 Times in 2,629 Posts
- Create a custom locking table. You'll need to program a timeout though; users whom sit too long in a particular form locking it will then be forced to re-enter the details again if the timeout should expire. That will be an annoyance, but its one of the ways to do it. You can also take a modified CRUD approach to this, any alterations can be detected prior to an create / update / delete, and can be acted on accordingly. For this, sessions will be necessary to pass information along about particular records; PHP doesn't really shine in this department.
- Thats a matter of retrieving detail information from the user in specific. If users log in from a specific location (based on their user information), you can detect this and populate templates as necessary.
header('HTTP/1.1 420 Enhance Your Calm');