Update_Stock Qty Question

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
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Update_Stock Qty Question

Post 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'";
			}
		}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply