A problem most siteengineers with a db should consider

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

A problem most siteengineers with a db should consider

Post by tores »

Hi

Let's say that a user of your site is in the middle of a several-pages-registration. On each page u store the values given by the user. Then suddenly, in the middle of the registration, the user exits your page. What about the now incomplete and useless values he's entered into your db?? How can these be removed?
Anyone got a solution to this problem. Is it possible to notify the server that the user is leaving and trigger a function of some sort that removes the values he entered?

regards tores
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Store a date/time in the database along with the first set of variables.
At the end of every day, run a page that deletes incomplete logins more than seven days old.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Why not store the data in session variable till the multi-page process is complete? Then session garbage collection can take care of the problem.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

..incomplete and useless values he's entered into your db??
It would never occur to me to enter any data into the db before the user has completed entering and indicated that he is finished. Why would anyone do that?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

It would never occur to me to enter any data into the db before the user has completed entering and indicated that he is finished. Why would anyone do that?
Experience is being able to say you made a mistake before. Wisdom is not repeating the same mistakes again.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: A problem most siteengineers with a db should consider

Post by JayBird »

tores wrote:Hi

Let's say that a user of your site is in the middle of a several-pages-registration. On each page u store the values given by the user. Then suddenly, in the middle of the registration, the user exits your page. What about the now incomplete and useless values he's entered into your db?? How can these be removed?
Anyone got a solution to this problem. Is it possible to notify the server that the user is leaving and trigger a function of some sort that removes the values he entered?

regards tores
It would never occur to me to enter data into a DB until whatever process was finished. Entering data into a DB would eb the last thing that would happen in the process.

Mark
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

On rare occasions (customer doesn't want it and will not accept anything to do with sessions, or legacy code where sessions are an absolute mess and shouldn't really be altered in any way shape or form) it is necessary to place data into a database when not complete. In this instance I would store the necessary data in a temporary area with a timestamp. Once the process is complete move the temporary values into the main db area. All temporary values lasting longer than 7 days or so get wiped via a cron job.

I agree sessions are the way to go but unfortunately what we all think is a good idea is sometimes not allowed :wink:
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

CoderGoblin wrote:On rare occasions (customer doesn't want it and will not accept anything to do with sessions, or legacy code where sessions are an absolute mess and shouldn't really be altered in any way shape or form) it is necessary to place data into a database when not complete. In this instance I would store the necessary data in a temporary area with a timestamp. Once the process is complete move the temporary values into the main db area. All temporary values lasting longer than 7 days or so get wiped via a cron job.

I agree sessions are the way to go but unfortunately what we all think is a good idea is sometimes not allowed :wink:
So true but aren't you just impementing a form of sessions though? Sure your gc is a cron job but isn't a session nothing more than an id, a timestamp and some data? But I agree workarounds are sometimes dictated by the customer and situation.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Buddha443556 wrote: So true but aren't you just impementing a form of sessions though? Sure your gc is a cron job but isn't a session nothing more than an id, a timestamp and some data? But I agree workarounds are sometimes dictated by the customer and situation.
The answer is yes, in reality you are but as far as any customer or "admin" person is concerned you don't use the word session. I have found with a lot of customers doing something similar to what is "dreaded", making sure you truthfully can say 'it does not use X' makes the customer happy whilst allowing maintainable and practical code.

In the short term (first customer contact) you have to develop trust. Later if you develop a good customer relationship and they trust you, you can start influencing their ways of looking at things. It is then you could start reintroducing the idea of "php sessions" pointing out how similar they are to what is currently going on and how it would be minor changes only to convert it and enhance things. The key is developing the trust.
Post Reply