Update_Stock Qty Question
Posted: Fri Jan 28, 2005 8:02 am
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'";
}
}