user2280352
user2280352

Reputation: 155

PHP-MYSQL - How to implement - "Record has been updated by another user"

I have an application that queries records from database and every record has an edit button.

Consider the following scenario with two users - U1 and U2:

1.U1 queries record no 1.He clicks on edit and changes some values.

2.Meanwhile U2 also tries to edit the same record and clicks Save.U2's changes are saved to database.

How can I implement the functionality in which, when U1 tries to save his changes ,he gets the following error "Record has been modified by another user.Query again to see the changes".

Note:I do not want either users to be prompted on click of Edit that it is being modified by another user.This is because it is also a View button.Do not want users to restrict their viewing. Any help would be great.

Thanks

Upvotes: 0

Views: 235

Answers (1)

John Conde
John Conde

Reputation: 219914

  1. When loading the data to be edited also save the last_updated time in a session variable.
  2. When saving the form, before you save it get the last_updated time again.
  3. If they match, save the form. If not, reject it as not being in sync.

Upvotes: 0

Related Questions