Page 1 of 1

Update_Stock Qty Question

Posted: Fri Jan 28, 2005 8:02 am
by mmc01ms
Hi guys, I was thinking that when a customer purchase an item from my site the qty of stock will depricate by the amount they have brought. I was wondering how i could code this and this is what i came up with for a function. Any ideas of any other ways or if this way wouldn't work. I don't have the other scripts done to test it yet but im sure it wouldn't work.

Code: Select all

function update_stock(){
			
			$link_id = db_connect();
			
			foreach($_SESSIONї'cart'] as $catno => $qty)
			{
				$detail = get_vinyl_details($catno);
				$query = "select stock_level from vinyls where catno = '$catno'";
				$result = mysql_query($query, $link_id);
				
				$newqty = $detailsї'stock_level'] - $result;
				
				$query = "update vinyls set stock_level = '$newqty'
							where catno = '$catno'";
			}
		}

Posted: Fri Jan 28, 2005 8:09 am
by feyd
you never perform the update query. It doesn't need the selection query.

I'd suggest not deducting inventory at the time of purchase, but at shipping.

If anything, I'd mark the inventory as pending removal. This way, if the inventory suddenly drops below the level of their request, we could send a notice stating as such as that the order has been moved to backordering, to be filled upon receipt of a new shipment of product.