View Full Version : lock a record from editing

12-24-2006, 11:54 AM
i have a form in an admin program i wrote that more then one people can be logged in and editing at the same time.
is it possible to make the form that it can detect if someone else has the saem form open and if so make it read only.

12-24-2006, 12:38 PM
You could do this by having a mySQL table called 'template_locked' and then set that table to the id of the person editing it, and then when the form is submitted/tried to edit it then have the script test this field and compare it against the user id.if it matches allow it to continue, if not exit we cant edit template.

12-24-2006, 12:39 PM
but how do I know they are editing?
it's just an html form that pulls the data from the db

12-24-2006, 12:50 PM
when the users clicks "edit" make the script query the database setting the template clicked to locked with there user id.

12-24-2006, 05:32 PM
but then if the session times out or they don't click save but just close the window then the record will be on edit forever wont' it?

12-24-2006, 06:16 PM
Well create an extra field when you set the id that locked it and put in that the time it was checked out at, then you check the id and the checkout time.
If no id set : can edit
If id set: check time
If time > 15mins ago : can edit
If time < 15mins ago : cannot edit

12-24-2006, 07:05 PM
is there anyway to clear it on timeout or when the browser is closed?

it's just that someone can be on the form for more then 15 mintues so that's not really the best way.

12-24-2006, 07:16 PM
Well the timestamp could only be updated on a submission by the user, i.e. them submitting the form, if the data entry takes longer then i think you would just have to use a longer time and accept the inconvenience of having to wait for it.
For your example of on the browser being closed at this point no information is sent to the server so it wouldn't be posible to remove the lock at this point.