Okay, so I'm doing an e-commerce website for my school project. Basic run down of the cycle is that the user logs in, views items, adds the items that he likes to his shopping cart, and checks out the items at the shopping cart.
Now, for the the add to items function, I have this:
mysql_connect($localhost,$privName,$privPass);
@mysql_select_db($database) or die("Unable to select database");
$result = mysql_query($sel_rfo7);
while ($row = mysql_fetch_array($result))
{
$itemChe[] = $row['cardAmount'];
}
echo '<font color="#FFFFFF" face="Verdana, Geneva, sans-serif">';
echo 'RF Online Points Card 1000';
echo '<br>';
echo 'Items remaining: ';
echo count($itemChe);
echo '</font>';
Basically, I have an array ($itemChe
) that adds the results of a query (a product). The count of this array is then used as "Quantity" of the product, as in, how many items are left. I have no problems in that array.
Now, when the user decides the amount of items he wants, he goes to the next page, which, supposedly adds the items to another array.
global $itemName;
global $itemQuan;
$itemName[] = "Flyff20";
$itemQuan[] = $itemtoBuy;
$_SESSION['nameItem'] = $itemName;
$_SESSION['quanItem'] = $itemQuan;}
And here in lies the problem. The $itemName
and $itemQuan
start with no values (they are passed from page to page via session), since the user does not have anything in his shopping cart yet. However, whenever I echo out the arrays via for loop, the first element in the arrays is always "Array". When the user adds an item, it only works the first time (so now the items in the array would be "Array", "Item A"). Any other attempts would simply overwrite "Item A".
Can anyone please tell me what I'm doing wrong, or why does the array overwrite the last item?