473,378 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Maintaining data integrity with multiple users

I'm working on a multi-user system that at times may result in 2 users
accessing the same screen. These screens allow the users to both view
and update data. The problem comes when you have user A and user B
viewing the same screen and user A submits his page that writes to the
database. User B is now viewing a screen with invalid data. How do I
prevent this scenario from happening with PHP?

I thought about using a lock flag in a database table that gets set
when a page loads but realized there's a problem if the page is closed
and the the lock flag never gets reset.

What should I be doing to handle a situation like this?

thanks,

~john

May 25 '06 #1
3 2611
>I'm working on a multi-user system that at times may result in 2 users
accessing the same screen. These screens allow the users to both view
and update data. The problem comes when you have user A and user B
viewing the same screen and user A submits his page that writes to the
database. User B is now viewing a screen with invalid data. How do I
prevent this scenario from happening with PHP?


PHP runs server-side. Once user B sees something on his browser,
you can't update the screen again until user B clicks something.
Just about any page displayed on a browser will eventually
become out of date (even one that says who's President of the USA).

You can, however, save all the *OLD* data values in the page (probably
in hidden fields) and when the user submits his update, check that
the values haven't been "changed behind his back" by looking at the
database again and reject or merge such changes. This also prevents
user B from submitting changes, pressing the BACK button, and
submitting the same page again (perhaps with further changes).
Deciding to merge the changes requires careful thought. *Independent*
changes (e.g. one customer service rep changes address, the other
adds a service) could possibly be allowed through.

Gordon L. Burditt

May 25 '06 #2
Hi There,

The way I work this problem is by using a timestamp field in the DB showing
when the record has been updated last. When a user views a record, the
timestamp is saved in a hidden field within the form. In the event the user
modifies the record, the timestamp within the form is compared to the
timestamp in the DB. If there is a difference then the user is notified with
an error message and is presented with the updated information.

Note that this only works well when there is small chance of data
contention. If users frequently run into the situation where the data they
are trying to modify is stale, they will begin to complain about
functionality of the system. In cases where there is a high chance of data
contention, I lean towards a system of record locking.

For record locking, there are two additional DB fields in addition to the
last updated field. The first field is a record lock timestamp and the
second is the record lock user id. When a user views a record, they are
presented with a screen where the data is not shown in editable form fields
but rather a data screen with a modify button usually located at the top.

If the user clicks on the modify button they are sent to a new page at which
point the script will verify the record lock timestamp. If the field is
null, then script will set the the the record lock timestamp and user id
with the current system time and the id of the user modifying the data and
then the user is presented with a editable form.

In the event the record lock timestamp is not null, the script first checks
to see if it is stale by comparing it to the current system time. I usally
allow 5 minutes for a record lock before it becomes stale. If the record is
stale, the script sets the record lock information to the new user and
presents the editable form. If the record lock is not stale, then the user
is presented with a message saying that the record is being edited by
another user.

When the user goes to save the modified record data, the script will verify
that the proper user is updating the record, otherwise an error is
presented.

When using record locking, it is important to have a timeout, otherwise you
will find yourself with situations where a user locks a record and then
exits the browser for some reason or another leaving DB records uneditable
until an admin removes the record lock.

Cheers,
James
May 25 '06 #3
I think the timestamp should work just fine... thanks.

May 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael | last post by:
I'd like to write a program to verify the consistency between various database replicas in our environment. The rules are as follows: - I'm given two servers, each with a database - I don't...
4
by: Itai | last post by:
I need to develop an internal messaging sub-system that is similar to a web mail application but without SMTP support (e.g message routes are confined to the webapp domain). The requirements are...
8
by: Steve Jorgensen | last post by:
Hi folks, I'm posting this message because it's an issue I come up against relatively often, but I can't find any writings on the subject, and I haven't been able to figure out even what key...
1
by: Diane Yocom | last post by:
I'm still very new to ASP.Net, so wanted to get some advice on how to solve the following design problem (sorry my explanation is so long): I'm developing an ASP.Net intranet app (using VB.Net...
9
by: Bob | last post by:
I have a sql command with a SearchDate parameter of type date. When I execute its stored procedure from Query Analyzer (to SS2K) with a date out of the valid datetime range, EXEC @SearchDate =...
7
by: John Pote | last post by:
Hello, help/advice appreciated. Background: I am writing some web scripts in python to receive small amounts of data from remote sensors and store the data in a file. 50 to 100 bytes every 5 or...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
4
by: Deus402 | last post by:
I am designing an employer database, and I had thought that my tabledesign was pretty sound, but a new revelation has ruined my design. What I guess i really need is a way to uniquely identify...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.