I have items in my MySQL DB. If someone wants to buy one I want to adjust the total once they have added this to thier session...

All good and easy.

However if say their session is not completed into and order how can i return this item or items to the original database???

    there is no real good way for it. As you cannot make sure that a user is logged in. You can keep track of the time for a session to expire, and -say it is 5 minutes of inactivity- run a CRON job every few minutes to verify for active sessions (This requires you to keep track of the active sessions in a table: Sessionid & last page load). Sessions that are not active anymore need to release their items (Obviously: You would need to create a session handler that stores session information for you).

    Alternatively: Do not remove items from the main database...

      Agreed.

      Do not update the stock count until the actual purchase.
      Just make sure to add a check before the purchase goes through to ensure stock still exists for the selected item.

        Write a Reply...