This topic is locked

Check against same record being updated by many users

3/5/2008 6:35:43 AM
PHPRunner General questions
L
Lisa2006 author

Table: booking

Fields: email, booking_accepted, booking_flag, etc.
I've set up a my site so that users go to EDIT Page and simply enter there email and tick the booking_accepted field.

The record is then updated with "booking_flag" being set to 1.
Here's the problem.

User1 goes to Edit Page for record, and simply leaves the record open.

User2 goes to Edit Page for the same record, enters there email and checks the booking_accepted field. User2 clicks SAVE, the record is updated with User2's details and the "booking_flag" field is set to '1'
User1 comes back from there coffee break and enters there email and checks the booking_accepted field. User1 clicks Save. At this point the previously stored User2 details are overwritten by User1.
I would like to find a way, whilst the Edit page is open to check against the field "booking_flag" = 1.

If "booking_flag" = 1 then i can redirect to an error page.

I need this to be applied at the Edit Page: Before record updated Event.
Your help would be much appreciated.
Lisa

J
Jane 3/6/2008

Hi,
unfortunately there is no good way to implement record locking via PHP and Web browser.

I recommend you to use MySQL resources for that:

http://dev.mysql.com/doc/refman/5.0/en/innodb-locks-set.html

S
steveh 4/18/2008

What you can do is to have a sequence field, then you increment the sequence on the update and use the old value in the where:
E.g.
update myTabel set Name='Fred',City='London',Sequence=Sequence+1 where ID=123 and Sequence=5
Then after the update you check the rows affected, if it's 0 then your record was modified and you generate an error message.
This would actually be a nice addition for phprunner, have a field attribute that says "this is the sequence field" and the handling for this built in with a customisable error message?
Steve