我这样做是为了打造工作,但我的“附加”职能似乎并没有奏效。 我在产品页上点击“附加项目”链接,然后把我带上车页。 但是,这页上没有任何东西。 我喜欢这样说,我可以看到,告诉我,应该做些什么纠正。
增加项目的功能:
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);
}
}
我只检查了我对数据库的368-cart表格,该表是空的。
mysql> select * from cs368_cart
-> ;
Empty set (0.00 sec)
因此,显然没有增加任何东西。 我想知道我的问问问是否正确?
我的表格:
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)
和我的图表;
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)
这是我的“智商” Id I have in a seperate php file, which is bieng known better by the php file with this AddItem function.
function GetCartId(){
if(isset($_COOKIE["cartId"])){
return $_COOKIE["cartId"];
}
else {
session_start();
setcookie("cartId", session_id(), time()+((3600*24)*30));
return session_id();
}