Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    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.
    OR
    implement something that allows multiple users to add/remove and edit entries without interfering with each other or corupting the data if thats possible.

    second
    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.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    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?

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    1. 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.
    2. 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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •