Ajax/JQuery database access/mutex

This is my first question so thank you for taking interest.

I have created an office scheduling program that uses jquery to post to a php file which then inserts an appointment into a pgsql database. This has not happened yet but I can foresee this problem in the future, if two office workers try to schedule an appointment in the same slot at the same time, this would create a race condition and one set of customer data would be lost, or at least id have to dig it out of a log. I was wondering if there was a flag I could set in the database, if I need to create some kind of gate-keeper program to control server connections, or if there is some kind of mutex/lock/semaphore I can use with javascript/php/sql to keep this race condition from occurring.

Thank you for taking interest, Ive looked everywhere for an answer but Google is of no help.

Answers


You can either lock it with a database flag, or a better strategy is to detect collisions, since this only happens in rare cases.

To detect the problem, you can save a timestamp from the database containing the last updated time. Send this along with the form, and compare the timestamp before you update the record. If the timestamp has changed, then present the user with all the data and ask them what they want to do. This offers a way for the second saving user to modify their changes based on the previously saved data if they wish.

There are other ways to solve this problem, and the proper solution depends the nature of the specific problem.


Need Your Help

EmptyResult jQuery callback issue with $.get

jquery asp.net asp.net-mvc

I have some code in a controller (HomeController.cs) that gets called from a $.get method in my view.

Limit UIAppearance proxy scope

ios uiappearance

I'm currently using the appearance proxy object for customising my application interface.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.