AddItem function does not seem to be working

fz89

New Member
I go this thing to sorta work but my AddItem function doesn't seem to work. I click the "add item" link on the products page and it takes me to the cart page. But nothing is on the cart page. I am hoping somoneone can see it and tell me what to do to correct it.The AddItem function:\[code\]function AddItem($itemId, $qty) { // Will check whether or not this item // already exists in the cart table. // If it does, the UpdateItem function // will be called instead // Check if this item already exists in the users cart table $result = mysql_query("select count(*) from cs368_cart where cookieID = '" . GetCartID() . "' and itemId = $itemId"); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart, // we will add it with an insert query mysql_query("insert into cs368_cart(cookieID, itemId, qty) values('" . GetCartID() . "', $itemId, $qty)"); } else { // This item already exists in the users cart, // we will update it instead UpdateItem($itemId, $qty); } }\[/code\]I just checked my cs368_cart tables of the database and it is empty.\[code\]mysql> select * from cs368_cart-> ;Empty set (0.00 sec)\[/code\]So apparently nothing is being added. I am wondering if my query is correct?My tables:\[code\]mysql> select * from cs368_products-> ;+--------+----------------+---------------------------------------------+-----------+| itemId | itemName | itemDesc | itemPrice |+--------+----------------+---------------------------------------------+-----------+| 1 | French Vanilla | A medium blend with a hint vanilla | 9.79 | | 2 | Hazelnut Cream | A light blend with a spicy note of Hazelnut | 9.69 | | 3 | Columbian | A medium-dark blend straight up | 9.89 | +--------+----------------+---------------------------------------------+-----------+3 rows in set (0.00 sec)\[/code\]and my cart tables;\[code\]mysql> show columns from cs368_cart;+----------+-------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+-------------+------+-----+---------+----------------+| cartId | int(11) | NO | PRI | NULL | auto_increment | | cookieId | varchar(50) | NO | | | | | itemId | int(11) | YES | | NULL | | | qty | int(11) | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+4 rows in set (0.00 sec)\[/code\]This is my GetCartId I have in a seperate php file which is bieng called correctly by the php file with this AddItem function.\[code\]function GetCartId(){ if(isset($_COOKIE["cartId"])){ return $_COOKIE["cartId"];}else { session_start(); setcookie("cartId", session_id(), time()+((3600*24)*30)); return session_id();}\[/code\]
 
Back
Top