i am using the following piece of code so that when you add an item to my php (4.06) and postgres shopping cart, it adds
to the quantity field if it already exists rather than adding another instance of the item. the problem i'm having is that for the number of items in my basket i have to repeat this script each time. i know that i should be able to carry out a general if statement to apply to all the variables but i cant make one work, could anyone offer any help?, Would really appreciate if someone could turn this piece of code into somethinmg that will apply to general variables as oppposed to specific ones.
thanks for taking your time to look through my code.
//search basket1 for previous additions
$searchbasket = "select productid from basket where productid like '%1'";
$dosearchbasket = pg_exec($DBconnection, $searchbasket);
//count number of rows returned from search result
$rowCounting = pg_numrows($dosearchbasket);
//if previous items exist, then update
if (($rowCounting>=1)&&($productid==1))
{
//**UPDATING
$Updatebasket = "update basket set quantity=$quantity where productid=$productid";
$doUpdateBasket = pg_exec($DBconnection, $Updatebasket);
if (!$doUpdateBasket)
{
print "<h2>Error adding it to the basket</h2>";
}
}
//if previous items do not exist, then insert
if (($rowCounting==0)&&($productid==1))
{
//**INSERTING
$addtobasket = "insert into basket values ($productid, $quantity)";
$doAddToBasket = pg_exec($DBconnection, $addtobasket);
if (!$doAddToBasket)
{
print "<h2>Error adding to the basket</h2>";
};
}