You are here: Re: Help please with the dreaded what if question « PHP Programming Language « IT news, forums, messages
Re: Help please with the dreaded what if question

Posted by Someuser on 05/28/06 18:01

In your DB, why not change the value stored in the DB from "pending sale" to
a timestamp and set a timeout period. Then have a function that updates all
the reserved timestamps for concerned user to the current time on every page
load by using a SQL update statement, this will keep the timestamp valid
while the user is online but should there be no activity for let say ten
minutes then the article reservation become stale. when verifing article
availability, you could show all non-reserved items as well as those whose
reservation has expired. You would also look at doing this in conjunction
with a session timeount to be consistant.

I would always try and avoid using simple flags when they are subject to
cause problems should the user just exit from a system. By using timestamps,
you avoid having to manually or using a cron script to correct database
integrity problems.

> if ($status=="pending sale"){
> echo "Sorry this item is temporarily unavailable";
> }

I would also avoid parsing a database within PHP but rather by using SQL
searches as doing this within PHP is less efficient. Imagine a DB with a
million records, retrieving a recorset that is larger than needed.

James

"Dynamo" <Dynamo_member@newsguy.com> wrote in message
news:e5blo90uc6@drn.newsguy.com...
> Hi again,
> I am constructing a site on a small scale where people can buy nik naks
> and pay
> for them via paypal. Everything works fine unless there is only one of an
> item
> left for sale. What if 2 people try to buy this item at the same time?
> I have partially overcome this problem by adding an extra column called
> status
> to my catalogue table. When somebody tries to buy the item I have created
> an
> interim page where the user is asked to confirm his purchase before
> sending the
> info to paypal and I have inserted an update query that changes the status
> from
> "available" to "pending sale" on this page. There is also an if statement
> like:
> if ($status=="pending sale"){
> echo "Sorry this item is temporarily unavailable";
> }
> else{
> ?>
> <form>
> // Send payment to paypal
> </form>
> <form method="post" action="cancelpurchase.php>
> // Cancel purchase
> </form>
> <?php
> }
> ?>
> If the user decides he doesn't want to purchase the cancelpurchase.php
> updates
> the status to "available".
>
> Again everthing works fine but what happens if the user doesn't choose
> either
> option and simply closes the open window? The status remains at "sale
> pending"
> and nobody can buy it.
> Any suggestions greatly appreciated
> Regards
> Dynamo
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация